Get all taggable_friends picture with FBSDKGraphRequest in swift

957 views Asked by At

I am trying to get all my taggable_friends profil picture in swift. With my code, I can obtain my taggable_friends' name, but I don't know how I can get their profil picture... Any idea how? Thanks!!!

var fbRequest = FBSDKGraphRequest(graphPath:"/me/taggable_friends", parameters: nil);
                fbRequest.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result : AnyObject!, error : NSError!) -> Void in

                    if error == nil {

                        var resultdict = result as! NSDictionary
                        var data : NSArray = resultdict.objectForKey("data") as! NSArray

                        for i in 0..<data.count {
                            let valueDict : NSDictionary = data[i] as! NSDictionary
                            let id = valueDict.objectForKey("id") as! String
                            let name = valueDict.objectForKey("name") as! String
                            // let url = valueDict.objectForKey("url") as! String  -- is not working

I already saw this topic: How can I retrieve friend's picture through FBRequest in swift but I still don't undersand how to do it...

2

There are 2 answers

2
Tobi On

Have a look at

The request should be something like this

graphPath:"/me/taggable_friends?fields=id,name,picture"
0
Ruben On

Not sure if this is the most effective way to do this, but the code works:

      func returnUserData()
{
    let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me/taggable_friends?", parameters: nil)
    graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in

        if ((error) != nil)
        {
            // Process error
            println("Error: \(error)")
        }
        else
        {
            println("fetched user: \(result)")

            var resultdict = result as! NSDictionary
            var data : NSArray = resultdict.objectForKey("data") as! NSArray

            for i in 0..<data.count {
                let valueDict : NSDictionary = data[i] as! NSDictionary
                let id = valueDict.objectForKey("id") as! String
                let name = valueDict.objectForKey("name") as! String
                let pictureDict = valueDict.objectForKey("picture") as! NSDictionary
                let pictureData = pictureDict.objectForKey("data") as! NSDictionary
                let pictureURL = pictureData.objectForKey("url") as! String
                println("Name: \(name) URL: \(pictureURL)")
            }

        }
    })
}