[Facebook-iOS-SDK 4.0]如何从FBSDKProfile获取用户电子邮件地址 [英] [Facebook-iOS-SDK 4.0]How to get user email address from FBSDKProfile
问题描述
我正在将我的应用升级到 Facebook-iOS-SDK-4.0 ,但似乎无法从FBSDKProfile
接收用户电子邮件,因为它仅提供用户名,用户名等
I'm upgrading my app to Facebook-iOS-SDK-4.0, but seems like I can't get user email from FBSDKProfile
, since it only provide, username, userid, etc.
推荐答案
要获取电子邮件,您需要使用图形API,特别是要提供填充有所需字段的parameter字段.看一下Facebook的Graph API探索工具,它可以帮助找出查询. https://developers.facebook.com/tools/explorer
To fetch email you need to utilize the graph API, specifically providing the parameters field populated with the fields you want. Take a look at Facebook's Graph API explore tool, which can help to figure out the queries. https://developers.facebook.com/tools/explorer
以下用于我获取电子邮件的代码如下,假定您已经登录:
The code that worked for me to fetch email is the following, which assumes you are already logged in:
NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
[parameters setValue:@"id,name,email" forKey:@"fields"];
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result, NSError *error) {
aHandler(result, error);
}];
这篇关于[Facebook-iOS-SDK 4.0]如何从FBSDKProfile获取用户电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!