Facebook page image returning null in FBSDKGraphRequest

I am trying to get an image from a facebook page. I got 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 message, but my result is zero. Pickup looks like this:

 /110475388978628/picture 

I copied the code directly from here , but it does not work. Any idea what I'm doing wrong? I have an access token, because I can get the page ID through a graph request

+6
source share
3 answers

If you want to get the image in the same query as the rest of the user information, you can do all this in a single 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 } }) 
+2
source

There are no parameters called "fields." replace ["fields": "data"] with nil

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

You can use the Graph API Explorer tool to first create a graph request: https://developers.facebook.com/tools/explorer

In this case, you will see that the graph path should just be the identifier of the object (i.e. your picPath should just be 110475388978628 , and your parameters should be [ "fields" : "picture"] .

Then you need to parse the "url" from result["picture"]["data"]["url"] .

+1
source

All Articles