IOS Facebook SDK:尽管授予了权限,但登录不会返回电子邮件 [英] IOS Facebook SDK: login doesn't return email despite permissions granted

查看:36
本文介绍了IOS Facebook SDK:尽管授予了权限,但登录不会返回电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 facebook sdk 获取信息,但到目前为止,我只获得了用户的 id 和姓名,尽管我确定有可用的电子邮件,因为它是我的帐户.我一直在这里查看几个答案,但到目前为止没有一个解决了我的问题.我做错了什么,为什么在我请求多个权限时没有返回更多数据?

I'm trying to get information through the facebook sdk but so far I'm getting only the id and the name of the user, although I'm sure there is an email available, as it is my account. I've been looking at several answer here but none of them solved my problem so far. What am I doing wrong, and why is it not returning more data as I am requesting several permissions?

这是我的代码:

fbLoginManager.logInWithReadPermissions(["public_profile", "email", "user_friends", "user_about_me", "user_birthday"], handler: { (result, error) -> Void in
        if ((error) != nil)
        {
            // Process error
            println("There were an error: (error)")
        }
        else if result.isCancelled {
            // Handle cancellations
            fbLoginManager.logOut()
        }
        else {
            var fbloginresult : FBSDKLoginManagerLoginResult = result
            if(fbloginresult.grantedPermissions.contains("email"))
            {
                println(fbloginresult)
                self.returnUserData()
            }
        }
    })

以及获取用户数据的函数:

And the function to get the user data:

func returnUserData()
{
    let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
    graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in

        if ((error) != nil)
        {
            // Process error
            println("Error: (error)")
        }
        else
        {
            println("fetched user: (result)")

            if let userName : NSString = result.valueForKey("name") as? NSString {
                println("User Name is: (userName)")
            }
            if let userEmail : NSString = result.valueForKey("email") as? NSString {
                println("User Email is: (userEmail)")
            }
        }
    })
}

哪个返回:

fetched user: {
id = 55555555;
name = "Kali Aney";
}
User Name is: Kali Aney

推荐答案

自 Graph-API 版本 2.4(Pod 版本 4.4.0)以来,Facebook Graph API 破坏了它的向后兼容性(当以默认方式使用时).

Facebook Graph API broke it’s backward compatibility (when used in a default fashion) Since Graph-API version 2.4 (Pod Version 4.4.0).

FB Graph-API 2.4 不会返回用户的所有默认字段

要解决此问题,您可以使用显式图形版本 2.3:

To resolve this you can either use explicitly graph version 2.3:

[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil tokenString:[FBSDKAccessToken currentAccessToken].tokenString version:@"v2.3" HTTPMethod:nil]

在这种情况下,FB 保证 v2.3 将在至少 2 年后推出.https://developers.facebook.com/docs/graph-api/overview:

in which case FB assures v2.3 will be available at least 2 years from now. https://developers.facebook.com/docs/graph-api/overview:

Graph API 有多个版本可供任何一个访问时间.每个版本都包含一组核心字段和边缘操作.我们保证这些核心 API 将可用并且自发布之日起至少 2 年内未在该版本中修改.这平台更改日志可以告诉您当前是哪些版本可用.

The Graph API has multiple versions available to access at any one time. Each version contains a set ofcore fields and edge operations. We make a guarantee that those core APIs will be available and un-modified in that version for at least 2 years from release. The platform changelog can tell you which versions are currently available.

您可以通过询问您感兴趣的特定字段来使用新的 Graph-API (v2.4):

you can use new Graph-API (v2.4) in by asking for specific fields you are interested in:

[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" 参数:@{@"fields" : @"email,name"}]

这篇关于IOS Facebook SDK:尽管授予了权限,但登录不会返回电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆