2

I'm trying to fetch facebook friendlist of a logged in user and it works fine in my account, but when I migrated the app details to a new account and changed the app ID and app secret I'm getting this error below

Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xf89c0b0 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ParsedJSONResponseKey={
    body =     {
        error =         {
            code = 100;
            message = "(#100) Unknown fields: username.";
            type = OAuthException;
        };
    };
    code = 400;
}, com.facebook.sdk:ErrorSessionKey=<FBSession: 0xe5a6c30, state: FBSessionStateOpen, loginHandler: 0xe58d5a0, appID: 705259966179163, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0xf87b180>, expirationDate: 4001-01-01 00:00:00 +0000, refreshDate: 2014-05-20 07:14:50 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
    status,
    permission
)>}

This is my current code for fetching friends

- (BOOL)retrieveFacebookFriendsForProfileId:(NSString *)fbProfileId completionBlock:(void (^)(NSArray *, NSError *))completionBlock
{

    [FBSession openActiveSessionWithReadPermissions:nil
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *session,
                                                      FBSessionState state,
                                                      NSError *error) {
                                      if (error) {

                                          NSLog(@"Error");
                                      } else if (session.isOpen) {

    [[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
        if (error) {
            //Throws the code 100 error here
            completionBlock(nil, error);
        }else{
            FBRequest* friendsRequest = [FBRequest requestForMyFriends];
            [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,NSDictionary* result,NSError *error) {
                if(error)
                    completionBlock(nil, error);
                else
                {
                    NSArray *friendJSONs = [result objectForKey:@"data"];

                    NSMutableArray *friends=[NSMutableArray array];
                    for(NSDictionary * friendDict in friendJSONs)
                    {
                        SocialProfile *friend=[[SocialProfile alloc] initWithDictionary:friendDict socialMedia:kSocialMediaFacebook];
                        [friends addObject:friend];
                    }
                    completionBlock(friends, nil);
                }
            }];
        }
    }];

                                      }
                                  }];
    return YES;
}

This code works fine if I use my old app Id and secret. I checked the setting in new account and everything is same as I have done in my old account I dont understand what the problem is. Any help is appreciated

Francis F
  • 3,157
  • 3
  • 41
  • 79
  • i am also getting same problem.whenever you are getting solution so, kindly share.. Thanks\ – Rahul Juyal May 20 '14 at 08:36
  • 2
    Did you request the user_friends permission? Apps created after 04/30 are subject to v2.0 of the Graph API, and you need to request the user_friends permission. With that permission, you will be able to get a list of the user's friends who are also using your app. – Ming Li May 20 '14 at 23:12
  • Wouldnt the [FBRequest requestForMyFriends] do that? – Francis F May 21 '14 at 04:45

1 Answers1

1

According to https://developers.facebook.com/docs/apps/changelog Friend list now only returns friends who also use your app: The list of friends returned via the /me/friends endpoint is now limited to the list of friends that have authorized your app.

So I changed my above code to this and it gave me list of friends that use the app and not the whole FB friendlist

FBRequest *friendsRequest = [FBRequest requestForGraphPath:@"/me/friends"];
Francis F
  • 3,157
  • 3
  • 41
  • 79
  • @Karun You can also refer this post http://stackoverflow.com/questions/23417356/facebook-graph-api-v2-0-me-friends-returns-empty-or-only-friends-who-also-u/29182403#29182403 – Jobins John Apr 20 '15 at 07:45