简体   繁体   English

Facebook SDK 4 iOS用户信息电子邮件阅读权限无效

[英]Facebook sdk 4 iOS user info email readpermissions dont work

I try to use the iOS Facebook SDK version 4. 我尝试使用iOS Facebook SDK版本4。

i completed the login without problem,but impossible to get user email adresse using graph API. 我完成了登录,没有问题,但是无法使用graph API获得用户电子邮件地址。 if someone have a solution for it can be very cool. 如果有人有解决方案可能会很酷。

here my code, in view did load : 这是我的代码,鉴于确实加载了:

_FBButton = [[FBSDKLoginButton alloc] init];
_FBButton.readPermissions = @[@"public_profile", @"email"];



_FBButton.delegate = self;

here the method when login success : 这里是登录成功的方法:

- (void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error: (NSError *)error{



 if ([FBSDKAccessToken currentAccessToken]) {       


    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
     startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result2, NSError *error) {

         if (!error) {
             NSLog(@"fetched user:%@", result2);
         }
     }];
  }
}

here the result : 结果如下:

 "first_name" = Jack;
gender = male;
id = 1381385368853232;
"last_name" = Ammer;
link = "https://www.facebook.com/app_scoped_user_id/1381385368853232/";
locale = "fr_FR";
name = "Jack Ammer";
timezone = 2;
"updated_time" = "2015-04-02T07:26:35+0000";
verified = 1;

so why i can get the email adresse ? 那为什么我可以获得电子邮件地址?

thanks in advance. 提前致谢。

EDIT 编辑

maybe the problem is caused because facebook ask user only for public profil,check the picture : why readpermissions dont work ? 也许是由于Facebook只要求用户提供公共档案引起的问题,请检查图片:为什么阅读权限无效?

在此处输入图片说明

i found the solution, i dont really know why exactly but it works ! 我找到了解决方案,我真的不知道为什么会这样,但是它有效! it's very easy, you should not initialise the Facebook Button when it added on storyboard. 这非常简单,将Facebook Button添加到情节提要上时,您不应该对其进行初始化。 To solve my problem i just comment the line where i initialise the button. 为了解决我的问题,我只需在初始化按钮的行中添加注释。

 //facebook
 // _FBButton = [[FBLoginView alloc] initWithReadPermissions:@[@"email"]];

 _FBButton.readPermissions = @[@"email"];
 _FBButton.delegate = self;

and now all works good ;) 现在一切正常;)

Check properly you must be getting user Email address into your console. 正确检查,您必须将用户电子邮件地址输入控制台。

Tried your code at my end and getting email address using FBSDKGraphRequest. 我在末端尝试了您的代码,并使用FBSDKGraphRequest获取了电子邮件地址。

The problem of mine is my facebook account did not have an verified email address (yes, this can happen!). 我的问题是我的facebook帐户没有经过验证的电子邮件地址(是的,这可能发生!)。 please check your profile setting page. 请检查您的个人资料设置页面。

for sdk 4x, you can make use of this 对于sdk 4x,您可以利用它

when you start to ask permission make it this way: (since graph api has been upgraded to 2.5 as of now in which email has not been made a default permission) 当您开始请求权限时,请按照以下方式进行操作:(由于图形api截至目前已升级到2.5,因此尚未将电子邮件设为默认权限)

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logInWithReadPermissions: @[@"public_profile", @"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
}];

and then inside that, continue like 然后在里面继续

if ([FBSDKAccessToken currentAccessToken])
             {
                 NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
                 [parameters setValue:@"id, name, email, gender" forKey:@"fields"];

                 [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters]
                  startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
// fetch all your datas
}];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM