Facebook SDK 3.0: how to receive user's e-mail?

前端 未结 5 1938
执笔经年
执笔经年 2020-12-04 20:07

In the \"old\" FB iOS SDK I could receive user information via the following:

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys         


        
5条回答
  •  猫巷女王i
    2020-12-04 20:38

    The easiest method for getting the info after logging in is :

    -(IBAction)loginWithFacebook:(id)sender{
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login
     logInWithReadPermissions: @[@"public_profile",@"email"]
     fromViewController:self
     handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
         if (error) {
             NSLog(@"Process error");
         } else if (result.isCancelled) {
             NSLog(@"Cancelled");
         } else {
             NSLog(@"Logged in");
             [self getFacebookProfileInfos];
    
         }
      }];
    }
    
    -(void)getFacebookProfileInfos {
    NSDictionary *parameters = @ {@"fields": @"id, name, first_name, last_name, picture.type(large), email"};
    if ([FBSDKAccessToken currentAccessToken]) {
        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error) {
                 NSLog(@"fetched user:%@", result);
             }
         }];
    }
    

    }

    You will get all the info the result.

提交回复
热议问题