我已经阅读了很多关于从Facebook获取信息的教程,但目前为止我失败了。我只想从Facebook获取用户名和个人资料照片。从Facebook获取用户名和个人资料图片iOS 7
- (IBAction)login:(id)sender {
[FBSession openActiveSessionWithReadPermissions:@[@"email",@"user_location",@"user_birthday",@"user_hometown"]
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
switch (state) {
case FBSessionStateOpen:
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
NSLog(@"error:%@",error);
} else {
// 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"]]);
}
}];
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
} ];
}
我使用此代码获取信息,但我无法获取任何信息。 你能帮我一下吗?或者你更喜欢教程来阅读它?我已阅读developer.facebook.com上的教程。
谢谢您的关注。
我需要这一代码之前做一些事情?因为当我点击按钮时,它不会去if语句。 –
那么,SDK教程(https://developers.facebook.com/docs/ios/ios-sdk-tutorial/)中介绍了一些初始化。我假设你已经遵循了这些步骤。 – Guilherme
我想我做到了:)。我从Facebook获得了一个appID,并且我在.plist文件中写了这些。这些足够了,还是需要在提取信息之前先登录? –