Facebook好友的ID无效

时间:2017-01-02 03:25:12

标签: ios swift facebook userid profile-picture

我正在尝试使用Facebook API吸引用户的朋友。这是我目前的代码:

FBSDKGraphRequest(graphPath:"/me/taggable_friends", parameters: ["fields":"first_name, last_name, id"]).start(completionHandler: { (connection, result, error) in
   if error == nil {
       if let results = result as? NSDictionary {
           let data = results["data"]!
           if let results = data as? [AnyObject] {
                for result in results {
                    let object = result as AnyObject
                    let firstName = object.object(forKey: "first_name") as! String
                    let lastName = object.object(forKey: "last_name") as! String
                    let id = object.object(forKey: "id") as! NSString
                    print(id)
                    let facebookProfileUrl = "http://graph.facebook.com/\(id)/picture?width=10000"

如您所见,我正在检索朋友的个人资料。检索到名字和姓氏很好,但我在个人资料图片方面遇到了问题。朋友的id似乎比我之前检索到的用户ID大。当我将链接放入浏览器时,我没有收到图像。我明白了:

{
   "error": {
      "message": "(#803) Some of the aliases you requested do not exist: *****The id I retrieved******",
      "type": "OAuthException",
      "code": 803,
      "fbtrace_id": "B92Y7XevOaL"
   }
}

在查找错误时,我在Facebook上看到了这一点:

  

您使用的Facebook页面或群组ID不正确或无效

如何解决此错误?谢谢!

1 个答案:

答案 0 :(得分:2)

您无法在API中的其他地方使用taggable_friends个ID。但是,您可以request the picture edge作为taggable_friends请求的一部分,将其添加到parameters数组中,即...

parameters: ["fields":"first_name, last_name, id, picture"]