1

I am trying to get list of friends using Facebook SDK with no luck.

This is the code I use:

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                              initWithGraphPath:@"me/friends"
                              parameters:@{@"fields": @"fields=id, first_name, last_name, birthday, gender, picture, devices"}
                              HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    if (error == nil) {
        NSArray* friends = [result objectForKey:@"data"];
    } else {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}];

This is the error I get:

2016-05-08 00:07:12.610 App2Gift[48103:676830] Failed getting friend list
2016-05-08 00:07:12.610 App2Gift[48103:676830] Error: Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=100, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
    body =     {
        error =         {
            code = 100;
            "fbtrace_id" = "G3OpyiU/JKs";
            message = "(#100) Unknown fields: fields=id.";
            type = OAuthException;
        };
    };
    code = 400;
}, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=(#100) Unknown fields: fields=id., com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0} {
    "com.facebook.sdk:FBSDKErrorDeveloperMessageKey" = "(#100) Unknown fields: fields=id.";
    "com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey" = 0;
    "com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode" = 100;
    "com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey" = 400;
    "com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey" =     {
        body =         {
            error =             {
                code = 100;
                "fbtrace_id" = "G3OpyiU/JKs";
                message = "(#100) Unknown fields: fields=id.";
                type = OAuthException;
            };
        };
        code = 400;
    };
}

Running the same with parameters as: nil works but doesn't give back all the needed data.

bashan
  • 3,572
  • 6
  • 41
  • 58

2 Answers2

1

Tested and working, with these permissions:

loginView.readPermissions = @[@"public_profile", @"email", @"user_friends"];

NSString *path = [NSString stringWithFormat:@"/me/friends"];

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                             initWithGraphPath:path
                             parameters:@{@"fields": @"id, name, picture, devices"}
                             HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) 
{

}];
norbDEV
  • 4,795
  • 2
  • 37
  • 28
0

In v2.0 of the Graph API, calling /me/friends returns the person's friends who also use the app.

In addition, in v2.0, you must request the user_friends permission from each user. user_friends is no longer included by default in every login. Each user must grant the user_friends permission in order to appear in the response to /me/friends. See the Facebook upgrade guide for more detailed information

nerowolfe
  • 4,787
  • 3
  • 20
  • 19
  • Thanks nerowlfe, but I still didnt get the connection between your answer and the error I get. In addition, I would like to get my friends list (isnt it one of the most trivial requests in Facebook api) , how can I do it? – bashan May 08 '16 at 05:20