这是我的代码。帮助我从我的 Facebook 帐户获取工作和机构详细信息。我做错了什么吗?
if result.token != nil {
let profileReq = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "email, first_name,last_name,id,work,education"])
let connection = FBSDKGraphRequestConnection()
connection.addRequest(profileReq, completionHandler: { (connection, result, error) -> Void in
if error == nil {
print("Graph Request Result: \(result)")
if let email = result.valueForKey("email") as? String {
//名字
let first_name = result.valueForKey("first_name") as! String
//姓氏
let last_name = result.valueForKey("last_name") as! String
//ID
let fb_id = result.valueForKey("id") as! String
//个人资料图片
let profile_pic = "http://graph.facebook.com/" + fb_id + "/picture?type=large"
//工作详情为数组
let wrkAr = NSMutableArray()
if let workAr = result.objectForKey("work") as? NSArray {
for i in 0..<workAr.count {
let obj = workAr.objectAtIndex(i) as! NSDictionary
var name = ""
if let employer = obj.objectForKey("employer") as? NSDictionary {
name = employer.valueForKey("name") as! String
}
var pos = ""
if let position = obj.objectForKey("position") as? NSDictionary {
pos = position.valueForKey("name") as! String
}
name = name + "_" + pos + "_" + "no"
wrkAr.addObject(name)
}
}
//教育详细信息作为数组
let eduAr = NSMutableArray()
if let educationAr = result.objectForKey("education") as? NSArray {
for i in 0..<educationAr.count {
let obj = educationAr.objectAtIndex(i) as! NSDictionary
var name = ""
if let school = obj.objectForKey("school") as? NSDictionary {
name = school.valueForKey("name") as! String
}
name = name + "_"
eduAr.addObject(name)
}
}
最佳答案
工作和教育详细信息权限需要为reviewed在您可以从用户个人资料中获取这些详细信息之前,请访问 Facebook。根据docs :
user_work_history
user_education_history
If your app requests this permission Facebook will have to review how your app uses it.
基本上你必须登录developers.facebook.com并请求 Facebook 审核该特定应用程序的这些权限。 Facebook 将在给予您批准之前审查您的隐私政策和使用条款。只有在此之后,您才能够从您的用户处检索该信息。
我会防御性地验证传入的值,尽管许多人在 Facebook 个人资料上将其留空。确保您考虑了 2 个字段的空/未定义值。
关于ios - 无法从 Facebook 帐户获取工作和机构详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36861513/