加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – IOS Facebook SDK:尽管授予许可,登录也不会返回电子邮

发布时间:2020-12-14 05:33:09 所属栏目:百科 来源:网络整理
导读:我正在通过Facebook sdk获取信息,但到目前为止,我只得到用户的身份和名称,尽管我确信有一个电子邮件可用,因为它是我的帐户.我一直在看几个答案,但是迄今为止还没有人解决我的问题. 我做错了什么,为什么我要求几个权限不会返回更多的数据? 这是我的代码: fb
我正在通过Facebook sdk获取信息,但到目前为止,我只得到用户的身份和名称,尽管我确信有一个电子邮件可用,因为它是我的帐户.我一直在看几个答案,但是迄今为止还没有人解决我的问题.
我做错了什么,为什么我要求几个权限不会返回更多的数据?

这是我的代码:

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()
            }
        }
    })

并获取用户数据的功能:

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破坏了它的向后兼容性(以默认方式使用).

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

要解决这个问题,您可以使用明确的图形版本2.3:

[FBSDKGraphRequest alloc] initWithGraphPath:@“me”参数:nil tokenString:[FBSDKAccessToken currentAccessToken] .tokenString版本:@“v2.3”HTTPMethod:nil]

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

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):

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读