【发布时间】:2014-06-23 16:14:51
【问题描述】:
这是我的代码:
NSArray *permissions = @[@"read_friendlists", @"email",@"user_about_me",@"user_status"];
// OPEN Session!
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// if login fails for any reason, we alert
if (error) {
//NSLog(@"error %@",error);
// show error to user.
} else if (FB_ISSESSIONOPENWITHSTATE(status)) {
// no error, so we proceed with requesting user details of current facebook session.
//NSLog(@"we are here");
//NSLog(@"----%@",[session accessTokenData].accessToken);
NSString *tok = [session accessTokenData].accessToken;
NSLog(@"tok 2");
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
NSLog(@"error:%@",error);
}
else
{
NSLog(@"all dat %@",user);
// retrive user's details at here as shown below
NSLog(@"FB user first name:%@",user.first_name);
NSLog(@"FB user last name:%@",user.last_name);
NSLog(@"FB user birthday:%@",user.birthday);
NSLog(@"FB user location:%@",user.location);
NSLog(@"FB user username:%@",user.username);
NSLog(@"FB user gender:%@",[user objectForKey:@"gender"]);
NSLog(@"email id:%@",[user objectForKey:@"email"]);
NSLog(@"location:%@", [NSString stringWithFormat:@"Location: %@\n\n",
user.location[@"name"]]);
}
}];
// [self promptUserWithAccountName]; // a custom method - see below:
}
}];
}
它似乎工作除了“用户名”是代码中最重要的部分!我错过了什么吗?我尝试了很多权限,但没有给出用户名。我总是得到零。有什么想法吗?
【问题讨论】:
-
您使用的是哪个版本的 SDK 和 API?用户名在 API 2.0 版中不存在,所有新应用都将默认使用该用户名,使用当前 SDK 版本的应用也将使用该用户名,除非它们在 API 调用中特别请求 1.0 版