简体   繁体   中英

Inviting friends to use my ios app via Facebook

I've just started working on an existing project where I'm supposed to add functionality to invite your Facebook friends to use the app. It's using Parse's PFFacebookUtils to connect, and I'm trying to use the Facebook API to get your entire friends list so you can select them and invite them to download and use the app.

Since the V2 API is this even possible? As far as I can tell you can only get a list of friends who have already used the app (useless), or you can get a list of "Invitable Friends" but only if it's a Facebook Canvas Game, which this app isn't. I thought that inviting people to use your App via Facebook was a pretty common bit of functionality, but has Facebook deprecated this ability? I'm hoping that somebody knows something I don't, and there is a way to achieve this.

Thanks in advance!

You should still be able to use the Requests dialog (which lets the user choose who to send the request to) for a new app without needing special permissions

The invitable friends API should only be needed if you're building your own interface and need to enumerate which users the user can send Requests to, the requests dialog itself should still work without that

The documentation for use of the Requests dialog is here https://developers.facebook.com/docs/games/requests/v2.0 The iOS specific tutorial has a usage example which covers a few use-cases: https://developers.facebook.com/docs/games/mobile/ios-tutorial#requests More reference documentation: https://developers.facebook.com/docs/ios/ui-controls#requestdialog

You should use Facebook GameRequest. It's fully controlled by Facebook and you are not needed to implement anything. You can specify few properties (such as the message of the request, title, filters, extra data which you can later use when the invited user installs your app, etc). You can also implement a delegate class, and get information regarding success or failure, how many friends were invited, etc.

Some basic iOS usage for example:

FBSDKGameRequestContent *gameRequestContent = [[FBSDKGameRequestContent alloc] init];
    gameRequestContent.message = @"Please come play <you_game> with me!";
    gameRequestContent.title = @"INVITE FRIENDS TO PLAY <your_game>";
    gameRequestContent.data = "some_extra_data_on_this_request"
    gameRequestContent.filters = FBSDKGameRequestFilterAppNonUsers; // filter says that only Non-App users will appear in the list

// implement delegate as well:
    MyGameRequestDialogDelegate* myGameRequestDialogDelegate = [[ MyGameRequestDialogDelegate alloc] init];

// show the game request dialog
    [FBSDKGameRequestDialog showWithContent:gameRequestContent delegate:myGameRequestDialogDelegate];

The delegate class:

@interface MyGameRequestDialogDelegate : NSObject < FBSDKGameRequestDialogDelegate >    

@end

@implementation MyGameRequestDialogDelegate

 - (void)gameRequestDialog:(FBSDKGameRequestDialog *)gameRequestDialog didCompleteWithResults:(NSDictionary *)results
 {
    NSLog(@"FBSDKGameRequest Success");

    NSArray* arr = [results objectForKey:@"to"];
    if (arr)
    {
       // get number of invited friends
       unsigned long count = [arr count];
    }
}

- (void)gameRequestDialogDidCancel:(FBSDKGameRequestDialog *)gameRequestDialog
{
    NSLog(@"FBSDKGameRequest User Cancelled");
}

- (void)gameRequestDialog:(FBSDKGameRequestDialog *)gameRequestDialog
         didFailWithError:(NSError *)error
{
    NSLog(@"FBSDKGameRequest Error: %@", error);
}

For full documentations see: https://developers.facebook.com/docs/games/services/gamerequests/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM