我一直在使用下面的代码从 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/