2015-05-14 69 views
0

我試圖使用新的Facebook 4.0 sdks,但我很困惑如何獲取名稱,一旦我成功獲得權限。由於某種原因,nslog返回空值?Facebook登錄返回空名稱結果

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); 

    }}]; 
+0

設置斷點和檢查什麼[FBSDKProfile currentProfile]使用LLDB –

+0

它返回NULL以及 –

+0

http://stackoverflow.com/questions/29292371/facebook-sdk-v4-0-就是在那個時候for-ios-fbsdkprofile-currentprofile-not-being-set看起來像是你的問題 –

回答

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"]; 
}}]; 
}}];