Facebook登录名返回null为名称结果

时间:2015-05-14 17:45:20

标签: ios facebook login sdk

我正在尝试使用新的Facebook 4.0 sdks,但是当我成功获得权限后,我对如何获取该名称感到很困惑。由于某种原因,nslog返回空值?

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logInWithReadPermissions:@[@"public_profile"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if (error) {
            // Process error           

        } else if (result.isCancelled) {
            // Handle cancellations

        } else {
        //success

            _nam = [FBSDKProfile currentProfile].name;
            NSLog(@"name %@", _nam);

     }}];

1 个答案:

答案 0 :(得分:0)

最终解决了这个问题。

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logInWithReadPermissions:@[@"public_profile"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if (error) {
            // Process error           

        } else if (result.isCancelled) {
            // Handle cancellations

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

             }
             else {
                 NSString *userID = [[FBSDKAccessToken currentAccessToken] userID];
                 NSString *userName = [result valueForKey:@"name"];
}}];
}}];