Not getting Email and public profile using Facebook 4.4.0 SDK

后端 未结 1 559
眼角桃花
眼角桃花 2020-12-03 19:55

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

NSArray *arrFBPerm         


        
相关标签:
1条回答
  • 2020-12-03 20:19

    With Facebook 4.4 SDK there is a slight change. You must have to request the parameter with the FBSDKGraphRequest which you want from Facebook account.

    In your code there is nil in parameters :

    Update your code with the parameters like as :

    [[[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 with Facebook with the use of Custom Button then you can use the complete code as follows :

    - (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 it will work for you.

    0 讨论(0)
提交回复
热议问题