Search code examples
iosswiftfacebookuseridprofile-picture

Invalid ID from Facebook friend


I am trying to get the user's friends using Facebook API. Here is my current code:

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"

As you can see, I am retrieving the friends' profiles. The first name and last name are retrieved fine, but I am having trouble with the profile picture. The id for the friend seems larger than the user id I retrieved earlier. When I put the link into the browser, I don't receive an image. I get this:

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

When looking up the error, I see this from Facebook:

The Facebook page or group ID you’re using is not correct or invalid

How can I resolve this error? Thanks!


Solution

  • You can't use taggable_friends IDs elsewhere in the API. You can, however, request the picture edge as part of the taggable_friends request by adding it to your parameters array, i.e...

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