2015-12-16 25 views
2

我正在使用下面的api調用來獲取用戶通過Facebook登錄的信息...如何獲取在iOS上通過Facebook登錄的用戶的名字?

首先我稱之爲FBSDKLoginManager的這種方法。

- (void)logInWithReadPermissions:(NSArray *)permissions 
       fromViewController:(UIViewController *)fromViewController 
         handler:(FBSDKLoginManagerRequestTokenHandler)handler; 

並且一旦登錄成功,我調用下面的方法。

NSMutableDictionary* parameters = [NSMutableDictionary dictionary]; 
    [parameters setValue:@"id,name,email,birthday,gender,education,work" forKey:@"fields"]; 
    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters] 
          startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id user, NSError *error) { 
           if (!error) { 
            [[CleverTap push] graphUser:user]; 
           } 
          }]; 

我的觀點是FBSDK包含一個名爲FBSDKProfile的類。 這有一些屬性,我可以使用像名字中間名和其他。我怎樣才能訪問這.. ..?因爲即使在登錄後,該類的共享實例也不會給我零。

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

我在這裏錯過了什麼..?

回答

2

你只需要用戶first_name在你的參數。

請看代碼示例,獲取的名字

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

     NSString *name; 
     if (!error) { 
      name = result[@"first_name"]; 
     } 
}]; 

如果想要另一個現場,看到這裏的列表:https://developers.facebook.com/docs/graph-api/reference/v2.2/user

+0

這工作,但我想以某種方式得到FBSDKProfile對象..但還是謝謝你。 –

相關問題