ios - 无法从 Facebook Graph 访问电子邮件

标签 ios swift facebook facebook-graph-api

我一直在使用下面的代码从 Facebook 图表中获取一些详细信息,

    func getFBUserData(){
    let parameters =  ["fields": "id, first_name, picture.type(large), email, last_name, gender"]
    let graphRequest = FBSDKGraphRequest(graphPath: "/me", parameters: parameters)
    graphRequest?.start { (connection, result, error) in
        if let error = error {
            print(error.localizedDescription)
            print("Data Not Received")
        } else {
            let userID = FBSDKAccessToken.current().userID
            let URL = "http://graph.facebook.com/\(userID)/picture?type=large"
            print(URL)

            let json = JSON(result)
            print("FB Json \(json)")
            let fid = json["id"].stringValue
            let email = json["email"].stringValue
            let name =  json["first_name"].stringValue
            let lName = json["last_name"].stringValue
            let sex = json["gender"].stringValue
            var imgURLString = "http://graph.facebook.com/" + fid + "/picture?type=large"
            print(imgURLString)


            self.UploadSocialAccount(name: name,lname: lName, email: email, picture: imgURLString, gender: sex)
            let manager = FBSDKLoginManager()
            manager.logOut()

        }
    }
}

出于某种原因,我可以获得除电子邮件之外的所有其他详细信息。 需要在函数中更改什么才能获取所有参数?

最佳答案

您是否已请求阅读电子邮件地址的许可?否则,您只能阅读 Facebook 的公开个人资料。要访问其他信息,您必须专门征求用户的许可。检查这个网站:

https://developers.facebook.com/docs/facebook-login/ios/permissions

“在发送 Graph API 请求之前,您应该检查必要的权限并在需要时请求它们。”

您希望在登录按钮中执行此操作,例如:

func presentFBButton() {
    let loginButton = FBSDKLoginButton()
    loginButton.delegate = self
    // Permissions below this comment
    loginButton.readPermissions = ["email", "public_profile"]

    view.addSubview(loginButton)
    loginButton.frame = CGRect(x: 50, y: self.view.center.y + 123, width: view.frame.width - 100, height: 38)
}

关于ios - 无法从 Facebook Graph 访问电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48418421/

相关文章:

ios - 如果应用程序是从后台打开的(不是在后台),如何刷新应用程序

objective-c - Objective-C JSON类型

ios - Swift - 设置位置

ios - 无法在 Swift 中从 UIView 呈现 AlertController

swift - Interface Builder 中自定义类的模块不正确

php - 如何使用 Codeigniter 保持 Facebook 登录?

ios - 无法识别的选择器已发送到实例Objective-C

ios - 如果文件存在,将图像添加到 collectionView Cell

php - 验证内容是否已在 Facebook 上共享

java - 适用于 Android 的 Facebook key 哈希