用facebook按钮自定义登录。没有得到名称和UserID以外的信息

时间:2016-01-15 19:02:00

标签: objective-c facebook-ios-sdk

我尝试使用Facebook SDK从我登录的用户那里收到电子邮件。以下是我的两种登录方法

-(void)loginButtonClicked {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions: @[@"public_profile", @"email", @"user_friends"]
 fromViewController:self
 handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
     if (error) {
         NSLog(@"Process error");
     } else if (result.isCancelled) {
         NSLog(@"Cancelled");
     } else {

         [self getFBUSerData];
         NSLog(@"Logged in");
     }
 }];
}


- (void) getFBUSerData {

if (FBSDKAccessToken.currentAccessToken != nil) {
    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
     startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

         if (!error) {
             NSLog(@"fetched user:%@  and Email : %@", result,result[@"email"]);
         }
     }];
    }
}

日志中的结果:

(lldb) po result 
{
id = 42357***4506554;
name = "Fname Lname";
}

但没有电子邮件或朋友列表。任何帮助如何获得这些?

1 个答案:

答案 0 :(得分:1)

您必须在getFBUserData()中分配所需的参数。

这样的事情:

- (void) getFBUSerData {

if (FBSDKAccessToken.currentAccessToken != nil) {
    NSDictionary *dict = [[NSDictionary alloc] initWithObjects:@[@"id, name, first_name, last_name, picture.type(large), email"] forKeys:@[@"fields"]];

    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:dict]
     startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

         if (!error) {
             NSLog(@"fetched user:%@  and Email : %@", result,result[@"email"]);
         }
     }];        }
}