0

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!

Pranav Wadhwa
  • 7,666
  • 6
  • 39
  • 61
  • 1
    Taggable_friends are for tagging people. Nothing else. Use /me/friends – WizKid Jan 02 '17 at 04:30
  • @WizKid I tried that; however, I received 0 results. Is there anything else I could use? – Pranav Wadhwa Jan 02 '17 at 15:31
  • @penatheboss `/me/friends` only shows you the user's friends *who also use the application*. `/me/taggable_friends` exists because a user's full friends list is considered private data by Facebook. There is no way to get a full friends list with IDs you can use in the API. – ceejayoz Jan 02 '17 at 15:36
  • Ok got it. Thanks! – Pranav Wadhwa Jan 02 '17 at 15:46

1 Answers1

2

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"]
ceejayoz
  • 176,543
  • 40
  • 303
  • 368