没有得到工作和从Facebook帐户的机构细节

时间:2016-04-26 09:57:36

标签: ios swift facebook-graph-api

这是我的代码。帮助我从我的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)
                        }
                    }

1 个答案:

答案 0 :(得分:0)

工作和教育详细信息权限必须由Facebook reviewed才能从用户个人资料中获取这些详细信息。根据{{​​3}}:

user_work_history
user_education_history
  

如果您的应用请求此权限,Facebook将不得不审核如何   你的应用程序使用它。

基本上您必须登录docs并请求Facebook审核该特定应用的权限。 Facebook将在您批准之前审核您的隐私政策和使用条款。只有在此之后,您才能从用户那里检索该信息。

虽然有很多人在他们的Facebook个人资料中留下那个空洞,但我会在防守上验证传入的价值。确保您考虑到2个字段的空/未定义值。