[英]iOS FBSDKLoginManager get email
I followed the Facebook tutorial for the SDK here: https://developers.facebook.com/docs/facebook-login/ios/v2.0 我在这里遵循了SDK的Facebook教程: https : //developers.facebook.com/docs/facebook-login/ios/v2.0
My problem is that I can get user informations but I cannot get the email, it's not in the current profile. 我的问题是我可以获取用户信息,但无法获取电子邮件,该电子邮件不在当前配置文件中。 I have the first name, last name, user id, etc..
我有名字,姓氏,用户ID等。
Where can I find the email field because when I do this "if ([result.grantedPermissions containsObject:@"email"])" 在哪里可以找到电子邮件字段,因为执行此操作时“如果([(result.grantedPermissions containsObject:@“ email”]))“
it tells me that the user has granted the email. 它告诉我用户已授予电子邮件。
Have you tried the following: 您是否尝试过以下方法:
if ([result.grantedPermissions containsObject:@"email"]) {
NSLog(@"Granted all permission");
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"%@",result);
}
}];
}
} else {
NSLog(@"Not granted");
}
add one parameter 'email' to get email of current user. 添加一个参数“ email”以获取当前用户的电子邮件。 From i think SDK version 4.9, 'fields' parameter is compulsory to get user email.
从我认为SDK版本4.9开始,“ fields”参数是获取用户电子邮件的必填项。 (I didn't check for the previous SDK versions though)
(虽然我没有检查以前的SDK版本)
if ([FBSDKAccessToken currentAccessToken])
{
NSDictionary *param = @{@"fields" : @"email"};
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:param] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"%@",result);
}
}];
}
Make user that you requested a permission for the email 使用户请求您的电子邮件权限
let requestMe:FBSDKGraphRequest = FBSDKGraphRequest.init(graphPath: "/me", parameters: ["fields": "id,email, first_name, last_name, gender, picture"])
let connection : FBSDKGraphRequestConnection = FBSDKGraphRequestConnection()
connection.add(requestMe, completionHandler: { (con, results, error) in
//access_token
if ((error) == nil)
{
let dic = results as! NSDictionary
let email = (dic.value(forKey: "email"))
}
else
{
}
})
connection.start()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.