Facebook iOS SDK - get friends list

后端 未结 11 1470
猫巷女王i
猫巷女王i 2020-12-07 12:41

Using the Facebook iOS SDK, how can I get an NSArray of all my friends and send them an invitation to my app? I am specifically looking for the graph path to ge

11条回答
  •  情歌与酒
    2020-12-07 12:50

    For Inviting non app friend -

    you will get invite tokens with the list of friends returned by me/invitable_friends graph api. You can use these invite tokens with FBWebDialogs to send invite to friends as below

    - (void) openFacebookFeedDialogForFriend:(NSString *)userInviteTokens {
    
        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       userInviteTokens, @"to",
                                       nil, @"object_id",
                                       @"send", @"action_type",
                                       actionLinksStr, @"actions",
                                       nil];
    
        [FBWebDialogs
         presentRequestsDialogModallyWithSession:nil
         message:@"Hi friend, I am playing game. Come and play this awesome game with me."
         title:nil
         parameters:params
         handler:^(
                   FBWebDialogResult result,
                   NSURL *url,
                   NSError *error)
         {
             if (error) {
                 // Error launching the dialog or sending the request.
                 NSLog(@"Error sending request : %@", error.description);
             }
             else
             {
                 if (result == FBWebDialogResultDialogNotCompleted)
                 {
                     // User clicked the "x" icon
                     NSLog(@"User canceled request.");
                     NSLog(@"Friend post dialog not complete, error: %@", error.description);
                 }
                 else
                 {
                     NSDictionary *resultParams = [g_mainApp->m_appDelegate parseURLParams:[url query]];
    
                     if (![resultParams valueForKey:@"request"])
                     {
                         // User clicked the Cancel button
                         NSLog(@"User canceled request.");
                     }
                     else
                     {
                         NSString *requestID = [resultParams valueForKey:@"request"];
    
                         // here you will get the fb id of the friend you invited,
                         // you can use this id to reward the sender when receiver accepts the request
    
                         NSLog(@"Feed post ID: %@", requestID);
                         NSLog(@"Friend post dialog complete: %@", url);
                     }
                 }
             }
         }];
    }
    

提交回复
热议问题