When loading the Facebook feeds from one page, if a picture exist in the feed, I want to display the large picture.
How can I get with the graph API
? The picture link in the feed is not the large one.
Thanks.
The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.
What is the Facebook API? The Facebook Graph API is an HTTP-based API that allows developers to extract data and functionality from the Facebook platform. Applications can use this API to programmatically query data, post in pages and groups, and manage ads, among other tasks.
The Graph API photo object has a picture
connection (similar to that the user object has):
“The album-sized view of the photo. […] Returns: HTTP 302 redirect to the URL of the picture.”
So requesting https://graph.facebook.com/{object-id-from-feed}/picture
will redirect you to the album-sized version of the photo immediately. (Usefull not only for displaying it in a browser, but also if f.e. you want to download the image to your server, using cURL with follow_redirect option set.)
Edit:
Beginning with API v2.3, the /picture
edge for feed posts is deprecated.
However, as a field the picture can still be requested – but it will be a small one.
But full_picture
is available as well.
So /{object-id-from-feed}?fields=picture,full_picture
can be used to request those, or they can be requested directly with the rest of feed data, like this /page-id/feed?fields=picture,full_picture,…
(additional fields, such as message etc., must be specified the same way.)
What worked for me :
getting the picture link from the feed and replacing "_s.jpg
" with "_n.jpg
"
OK, I found a better way. When you retrieve a feed with the graph API, any feed item with a type of photo
will have a field called object_id
, which is not there for plain status
type items. Query the Graph API with that ID, e.g. https://graph.facebook.com/1234567890
. Note that the object ID isn't an underscore-separated value like the main ID of that feed item is.
The result of the object_id
query will be a new JSON dictionary, where you will have a source
attribute containing a URL for an image that has so far been big enough for my needs.
There is additionally an images
array that contains more image URLs for different sizes of the image, but the sizes there don't seem to be predictable, and don't all actually correspond to the physical dimensions of the image behind that URL.
I still wish there was a way to do this with a single Graph API call, but it doesn't look like there is one.
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