Facebook SDK 3.0:如何接收用户的电子邮件? [英] Facebook SDK 3.0: how to receive user's e-mail?
问题描述
NSMutableDictionary * params = [NSMutableDictionary字体大小:
@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
或那些还是完全不一样的组合?
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。
不要忘记要求电子邮件权限:
NSArray * permissions = [[NSArray alloc] initWithObjects:@email,nil];
[FBSession sessionOpenWithPermissions:permissions completionHandler:
^(FBSession * session,FBSessionState state,NSError * error){
[self facebookSessionStateChanged:session state:state error:error];
}];
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];
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"];
}
}];
}
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屋!