How to invite friends to my application via facebook iOS SDK and Graph API

27,606

Solution 1

It's simple you can just write the below code for personalised message and also you can easily select the friend's to whom the request should be sent, it's an straight forward and powerful method.

 [FBWebDialogs
 presentRequestsDialogModallyWithSession:nil
 message:NSLocalizedString(@"FBinviteMessage", nil)
 title:nil
 parameters:nil
 handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {}
];

Just add this six line of code to your Button action method, then the rest will be done by the IOS & FaceBook Inbuilt framework :)

Solution 2

You can do something like this:

Facebook* facebook = 
   [[Facebook alloc] initWithAppId:@"YOUR_FACEBOOK_APP_ID" andDelegate:self];

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       @"My Title", @"title",
                                       @"Come check out my app.",  @"message",
                                       @"FACEBOOK_USER_ID", @"to",
                                       nil]; 

[facebook dialog:@"apprequests" andParams:params andDelegate:self];

You can see the list of possible parameters at this page (scroll down): http://developers.facebook.com/docs/reference/dialogs/requests/

Solution 3

Today with the 3.11 version of the facebook SDK you should use this in order to send an app request to a specific friend.

NSString *facebookID = @"YOUR_FRIEND_FACEBOOK_ID"
NSMutableDictionary* params =
[NSMutableDictionary dictionaryWithObject:facebookID forKey:@"to"];

NSString *message = @"SOME_MESSAGE";
NSString *title = @"TITLE";


FBSession *facebookSession = [PFFacebookUtils session]; //You may changed this if you are not using parse.com

[FBWebDialogs presentRequestsDialogModallyWithSession:facebookSession
                                              message:message
                                                title:title
                                           parameters:params handler:
 ^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
 {

 }];

Solution 4

Facebook SDK 4.0 introduced "App Invites for iOS". Check it out: https://developers.facebook.com/docs/app-invites/ios

Solution 5

Make sure your facebook app id is same in both developer page and info in xcode next, enable sandbox mode and must fill canvas url [under app on facebook category] in developer page.

NSString *facebookID = @"Your friend facebook id";;
    NSMutableDictionary* params =
    [NSMutableDictionary dictionaryWithObject:facebookID forKey:@"to"];

    NSString *message = @"SOME_MESSAGE";
    NSString *title = @"TITLE";

    [FBWebDialogs presentRequestsDialogModallyWithSession:nil
                  message:message
                title:title
                parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                        if (error)
                    {
                    // Case A: Error launching the dialog or sending request.
                        NSLog(@"Error sending request.");
                    }
                    else
                    {
                        if (result == FBWebDialogResultDialogNotCompleted)
                    {
                    // Case B: User clicked the "x" icon
                        NSLog(@"User canceled request.");
                    }
                    else
                    {
                        NSLog(@"Request Sent. %@", params);
                    }
        }}];
Share:
27,606
zeevblu
Author by

zeevblu

Updated on May 27, 2020

Comments

  • zeevblu
    zeevblu almost 4 years

    I'm writing an iPhone application.

    I want to give the user the option to invite friends to start using my application via Facebook.

    More specifically I want to present a dialog that will let the user to select specific friends to invite.

    How can I do this?

    Thanks.