我正在尝试使用新的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);
}}];
答案 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"];
}}];
}}];