我正在尝试在登录后从Facebook获取用户名,电子邮件和图片。登录和权限工作正常。
我尝试使用:
FBSession
但我正在试图实施"user of undeclared FBSession"
:
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user,
NSError *error) {
if (!error) {
NSString *firstName = user.first_name;
NSString *lastName = user.last_name;
NSString *facebookId = user.id;
NSString *email = [user objectForKey:@"email"];
NSString *imageUrl = [[NSString alloc] initWithFormat: @"http://graph.facebook.com/%@/picture?type=large", facebookId];
}
}];}
在此处找到:How to get user info from Facebook SDK in iOS?
任何想法我怎么能做到这一点?或者为什么我对Facebook元素不公开?
答案 0 :(得分:0)
如果您使用的是新的facebook sdk和新的图表api,则必须使用访问令牌
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"picture,email,birthday,gender,name"}] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id res, NSError *error)
{
if (!error) {
FBID = [res objectForKey:@"id"];
FBDOB = [res objectForKey:@"birthday"];
FBEMAIL = [res objectForKey:@"email"];
FBGENDER = [res objectForKey:@"gender"];
FBUSERNAME = [res objectForKey:@"name"];
}
else
{
NSLog(@"%@", [error localizedDescription]);
}}];
}
查看从facebook获取数据的链接 https://developers.facebook.com/docs/ios/graph