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
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.
The Graph API is free to use, for all applicable use cases.
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
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With