连接所有facebook朋友ID

时间:2014-05-16 16:41:18

标签: objective-c facebook facebook-ios-sdk

我试图在我的iOS应用中邀请所有朋友,但当我尝试连接所有用户时#39;朋友邀请他们,字符串facebookID返回' null'。

这是我的代码:

-(void)inviteAllFriends {

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

    //ADD FRIENDS

    FBRequest* friendsRequest = [FBRequest requestForMyFriends];
    [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
                                                  NSDictionary* result,
                                                  NSError *error) {
        NSArray* friends = [result objectForKey:@"data"];
        NSLog(@"Found: %i friends", friends.count);

        NSMutableString *facebookID;

        for (NSDictionary<FBGraphUser>* friend in friends) {

            NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);
           facebookID = [facebookID stringByAppendingString:friend.id];

        }

        NSLog(@"ids %@", facebookID);
        //NSString *facebookID = @"100003355638755, 100000200918206";
        NSMutableDictionary* params =
        [NSMutableDictionary dictionaryWithObject:facebookID forKey:@"to"];

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

         }];

    }];
}

0 个答案:

没有答案