Don't receive email and public profile using Facebook 4.4.0 SDK

I am currently working on Facebook SDK 4.4.0. Before 4.4.0, in 4.3.0 we received an email, public_profile with the following code

NSArray *arrFBPermission = [[NSArray alloc]initWithObjects:@"email",@"public_profile", nil];
    [loginUsingFB logInWithReadPermissions:arrFBPermission handler:^(FBSDKLoginManagerLoginResult *result, NSError *error){ 
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error){
                      if (!error){
                          NSString *fnm = [result valueForKey:@"first_name"];
                          NSString *lnm = [result valueForKey:@"last_name"];
                      }
else{
     Nslog("%@", error localizedDescription);
}
                  }];
}

      

Now in the new SDK (i.e. 4.4.0) I am not getting these values. What for? I want email, first_name, last_name, id from Facebook.

+3


source to share


1 answer


There is a small change as of Facebook 4.4 SDK. You need to request the c parameter FBSDKGraphRequest

that you want to get from your Facebook account.

Your code has nil

in parameters:

Update your code with options like:

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location , friends ,hometown , friendlists"}]

      



If you want to login to Facebook with a custom button, you can use the complete code like this:

- (IBAction)btnFacebookPressed:(id)sender {
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    login.loginBehavior = FBSDKLoginBehaviorBrowser;
    [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
     {
         if (error)
         {
             // Process error
         }
         else if (result.isCancelled)
         {
             // Handle cancellations
         }
         else
         {
             if ([result.grantedPermissions containsObject:@"email"])
             {
                 NSLog(@"result is:%@",result);
                 [self fetchUserInfo];
                 [login logOut]; // Only If you don't want to save the session for current app
             }
         }
     }];
}
-(void)fetchUserInfo
{
    if ([FBSDKAccessToken currentAccessToken])
    {
        NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);

        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error)
             {
                 NSLog(@"resultis:%@",result);

             }
             else
             {
                 NSLog(@"Error %@",error);
             }
         }];
    }
}

      

I hope this works for you.

+19


source







All Articles