Facebook iOS SDK - get friends list

后端 未结 11 1453
猫巷女王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 13:00

    Use the function below to asynchronously fetch user's friends stored in an NSArray:

    - (void)fetchFriends:(void(^)(NSArray *friends))callback
    {
        [FBRequestConnection startForMyFriendsWithCompletionHandler:^(FBRequestConnection *connection, id response, NSError *error) {
            NSMutableArray *friends = [NSMutableArray new];
            if (!error) {
                [friends addObjectsFromArray:(NSArray*)[response data]];
            }
            callback(friends);
        }];
    }
    

    In your code, you can use it as such:

    [self fetchFriends:^(NSArray *friends) {
        NSLog(@"%@", friends);
    }];
    

提交回复
热议问题