Facebook SDK 3.0:如何接收用户的邮件? [英] Facebook SDK 3.0: how to receive user's e-mail?
问题描述
在旧"FB iOS SDK 中,我可以通过以下方式接收用户信息:
In the "old" FB iOS SDK I could receive user information via the following:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"SELECT uid, name, email, pic FROM user WHERE uid=me()", @"query",
nil];
JBFacebookManager *fbManager = [JBFacebookManager getInstance];
fbManager.requestDelegate = self;
[fbManager.facebook requestWithMethodName:@"fql.query"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
如何使用新的 FB iOS SDK 3.0 做到这一点?我是否需要使用 FBRequest
或 FBOpenGraphAction
或 FBGraphObject
或它们的组合或完全不同的东西?
How can I do this with the new FB iOS SDK 3.0? Do I need to use FBRequest
or FBOpenGraphAction
or FBGraphObject
or a combination of those or something completely different?
推荐答案
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
self.nameLabel.text = user.name;
self.emailLabel.text = [user objectForKey:@"email"];
}
}];
}
由于 FBGraphUser
没有电子邮件 @property
,我们无法访问名称(点语法)等信息,但是 NSDictionary 仍然有电子邮件 kv 对,我们可以像使用普通 NSDictionary 一样访问它.
Because FBGraphUser
doesn't have an email @property
, we can't access the information like with the name (dot-syntax), however the NSDictionary still has the email kv-pair and we can access it like we would do with a normal NSDictionary.
但不要忘记请求电子邮件许可:
Don't forget to ask for the email permission though:
NSArray *permissions = [[NSArray alloc] initWithObjects:@"email", nil];
[FBSession sessionOpenWithPermissions:permissions completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
[self facebookSessionStateChanged:session state:state error:error];
}];
这篇关于Facebook SDK 3.0:如何接收用户的邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!