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
? T
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.
Actually, you need two different solutions to fully fix this.
1] https://graph.facebook.com/{object_id}/picture
This solution works fine for images and videos posted to Facebook, but sadly, it returns small images in case the original image file was not uploaded to Facebook directly. (When posting a link to another site on your page for example).
2] The Facebook Graph API provides a way to get the full images in the feed itself for those external links. If you add 'full_picture' to the fields like in this example below when calling the API, you will be provided a link to the higher resolution version.
https://graph.facebook.com/your_facebook_id/posts?fields=id,link,full_picture,description,name&access_token=123456
Combining these two solutions I ended up filtering the input in PHP as follows:
if ( isset( $post['object_id'] ) ){
$image_url = 'https://graph.facebook.com/'.$post['object_id'].'/picture';
}else if ( isset( $post['full_picture'] ) ) {
$image_url = $post['full_picture'];
}else{
$image_url = '';
}