Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the large picture from feed with graph api?

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.

like image 1000
user1105951 Avatar asked Mar 02 '12 03:03

user1105951


People also ask

What data can I get from Facebook Graph API?

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 API in fb?

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.


3 Answers

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.)

like image 136
CBroe Avatar answered Oct 09 '22 09:10

CBroe


What worked for me : getting the picture link from the feed and replacing "_s.jpg" with "_n.jpg"

like image 24
user1105951 Avatar answered Oct 09 '22 09:10

user1105951


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.

like image 20
JK Laiho Avatar answered Oct 09 '22 09:10

JK Laiho