41.1. Facebook App Invite SDK Example

41.1. Facebook App Invite SDK Example

 


41.1.1. Show game notification dialog to invite friends

'ExecuteGraphRequest', 'ShowGameRequestDialog' are Deprecated.

The Facebook SDK is included in the Kakao Game SDK. Developers use the required Facebook API directly.
Below is an example of exposing a friend who is not registered to your game on Notification UI and sending a message. For more information, see the Facebook Developer Site.

Unity

using Facebook.Unity;     FB.AppRequest("Test message", null, new List<object>() { "app_non_users" }, null, null, null, "Test Title", AppRequestCallback);  // Use "app_users" if you want to display a list of unjoined friend filters and subscribed friends.     private void AppRequestCallback(IAppRequestResult result) {     Debug.Log("App Request result : " + result.RawResult); }

Android

   GameRequestDialog requestDialog; CallbackManager callbackManager;   public void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   FacebookSdk.sdkInitialize(this.getApplicationContext());     callbackManager = CallbackManager.Factory.create();   requestDialog = new GameRequestDialog(this);     requestDialog.registerCallback(callbackManager,     new FacebookCallback<GameRequestDialog.Result>() {     public void onSuccess(GameRequestDialog.Result result) {         String id = result.getId();         // Recipients List         List<String> recipients = result.getRequestRecipients();     }       public void onCancel() {         // Canceled     }       public void onError(FacebookException error) {         // Error     }     }   ); }   private void onClickRequestButton() {   GameRequestContent content = new GameRequestContent.Builder()     .setMessage("Come play this level with me")     .setFilters(GameRequestContent.Filters.APP_NON_USERS) // For unregistered friends list. Use "APP_USERS" if you want to show a list of your friends who have been registered.     .build();   requestDialog.show(content); }   protected void onActivityResult(int requestCode, int resultCode, Intent data) {   super.onActivityResult(requestCode, resultCode, data);   callbackManager.onActivityResult(requestCode, resultCode, data); }

iOS

// Set corresponding dialogCompensationHandler as variable within class void(^_dialogCompletionHandler)(NSError *, NSArray *facebookIds);     - (void)showGameRequestDialogWithCompletionHandler:(void(^)(NSError *error, NSArray *facebookIds))completionHandler {     FBSDKGameRequestContent *gameRequestContent = [[FBSDKGameRequestContent alloc] init];     // Look at FBSDKGameRequestContent for futher optional properties     gameRequestContent.message = @"YOUR_MESSAGE_HERE";     gameRequestContent.title = @"OPTIONAL TITLE";     gameRequestContent.filters = FBSDKGameRequestFilterAppNonUsers; // Use 'FBSDKGameRequestFilterAppUsers' to display unjoined friend filters and a list of subscribed friends.       // Assuming self implements <FBSDKGameRequestDialogDelegate>     // Define <FBSDKGameRequestDialogDelegate> in the class calling this api     FBSDKGameRequestDialog* dialog = [[FBSDKGameRequestDialog alloc] init];     [dialog setContent:gameRequestContent];     [dialog setDelegate:self];           if ([dialog canShow] == YES)         [dialog show];           if (completionHandler != nil)         _dialogCompletionHandler = completionHandler; }    // The delegate that is called after selecting a peer friend in the selection window. - (void)gameRequestDialog:(FBSDKGameRequestDialog *)gameRequestDialog didCompleteWithResults:(NSDictionary *)results {     // Set the corresponding completionHandler and return it     NSArray* recipients = (NSArray*)results[@"to"];        _dialogCompletionHandler(nil, recipients); }    // The delegate that is called when an error occurs after selecting a fellow friend in the selection window. - (void)gameRequestDialog:(FBSDKGameRequestDialog *)gameRequestDialog didFailWithError:(NSError *)error {     _dialogCompletionHandler(error, [NSArray array]); }     // The delegate that is invoked when Cancel is pressed in the selection window. - (void)gameRequestDialogDidCancel:(FBSDKGameRequestDialog *)gameRequestDialog {     // Cancel error return     _dialogCompletionHandler([KGError errorWithDomain:KGErrorDomain code:KGErrorUserCanceled description:@"User canceled."], [NSArray array]); }

41.1.2. Using Facebook graph API (Deprecated)

Unity

Android

iOS

41.1.3. Sending an message using the Facebook Game Request API (Deprecated)

Various methods of sending message can be used by using Graph API.

Examples)

  • Get a list of friends who are able to invite and send messages with the Graph API: Invite messages

  • Get a list of game Friends and send messages with Graph API: Normal Game Messages

Here is an example of sending a message using the Facebook Game Request API.

 

Unity

Android

iOS