简体   繁体   中英

How to fetch Friend list from facebook in iOS 9 fb sdk 4.8 or above?

I am using way mentioned below to find friend list but it is not working. And earlier methods i used (FBRequestConnection) is not working any more may be they are not supported any more. Please guide.

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/friends" parameters:@{@"fields": @"name"} HTTPMethod:@"GET"];
                 [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                     // TODO: handle results or error of request.
                     NSLog(@"request friend list:%@", request);
                 }];

Respsonse i got from this is:

request friend list:<FBSDKGraphRequest: 0x7fc77af33bc0, graphPath: /me/friendlists, HTTPMethod: GET, parameters: {
"access_token" = CAAIDdxjgZCZAQBAIupnz8fToFBh4YzgdvTAVciQZAZBj1kX8h7iZCYc1WSqVBVmmiCKRuAbymzRVcQeLZAIhhssc6JkB50rsOFJK6KwsuEiK6B1jvPuaUNZAIm2YqlZCg1INs9ZCoyqOo6lmRjjkttxX2RrkWZAUEDxE8lP9DApbyDh5ZChbsPT5zZAsdRMj3tQkVxLXyLaMXxN9rbPxU8lZCs57HbhOQXmkZD;
fields = name;
format = json;
"include_headers" = false;
sdk = ios;
}>

First of all need to pass the permission parameter "user_friends" at the time of login.Then use the below code to get list.

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/friends" parameters:@{@"fields": @"name"} HTTPMethod:@"GET"];
                 [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                     // TODO: handle results or error of request.
                     NSLog(@"request friend list:%@", result);
                 }];

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