Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Page Image returning null in FBSDKGraphRequest

I am attempting to retrieve the image from a facebook page. I have retrieved the page ID, and now I need to use this ID to get the image from the page. I am using the following code:

let pictureRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: picPath, parameters: ["fields" : "data"], HTTPMethod: "GET")
                            pictureRequest.startWithCompletionHandler({ (connection: FBSDKGraphRequestConnection!, result, error) -> Void in
                                if (error != nil) {
                                    print("picResult: \(result)")
                                } else {
                                    print(error!)
                                }
                            })

I am not getting an error, but my result is null. The picpath looks like this:

/110475388978628/picture

I copied the code directly from here but it isn't working. Any Idea what I'm doing wrong? I have the access token because I am able to get the page ID through the graph request

like image 625
arc4randall Avatar asked May 08 '16 15:05

arc4randall


People also ask

How do I get Facebook posts on API?

Your app needs user_posts permission from the person who created the post or the person tagged in the post. Then your app can read: Timeline posts from the person who gave you the permission. The posts that other people made on that person Timeline.

Is the Facebook API free?

The Graph API is free to use, for all applicable use cases.


1 Answers

If you want to get the picture in the same request as the rest of the users information you can do it all in one graph request.

let request = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email, picture.type(large)"])
request.startWithCompletionHandler({ (connection, result, error) in
    let info = result as! NSDictionary
    if let imageURL = info.valueForKey("picture")?.valueForKey("data")?.valueForKey("url") as? String {
        //Download image from imageURL
    }
})
like image 70
Micah Wilson Avatar answered Oct 05 '22 13:10

Micah Wilson