Graph API: Retrieving Image Sizes in a Page Feed

I use the Graph API to get a message about a fan page wall.

I noticed that the iOS app for Facebook can determine the exact ratio for its placeholder.

enter image description here

http://developers.facebook.com/tools/explorer?method=GET&path=facebook%2Ffeed%3Ffields%3Dpicture

{ "data": [ { "picture": "http://photos-b.ak.fbcdn.net/hphotos-ak-frc1/247019_457846347622804_946521095_s.jpg", "id": "20531316728_10151883063741729", "created_time": "2013-05-02T16:57:25+0000" }, : : : { "picture": "http://photos-e.ak.fbcdn.net/hphotos-ak-ash4/223257_10151498310776729_930531604_s.jpg", "id": "20531316728_10151498193061729", "created_time": "2012-10-05T18:42:38+0000" } ], "paging": { "previous": "https://graph.facebook.com/20531316728/feed?fields=picture&limit=25&since=1367513845", "next": "https://graph.facebook.com/20531316728/feed?fields=picture&limit=25&until=1349462557" } } 

There it does not contain image measurement information in the API response, and I would like to have the correct placeholder size with my user client, for example, the iOS application for Facebook.

I tried adding / facebook / feed? fields = picture, width, height , but you cannot find the relevant information.

Is there a way to restore the height and width parameters of images from the API itself?

+7
source share
2 answers

No, the API does not return ALL image sizes based on the post feed from / page _id / feed or the feed table.

I mentioned everything because you can do this:

 SELECT post_id, created_time, actor_id, attachment, message FROM stream WHERE source_id=PAGE_ID AND created_time<now() LIMIT 50 

If the message type is a photograph: enter image description here

If the message type is video: enter image description here

If the message type is a link starting with fbexternal (extract w and h parameter): enter image description here

If the post type is a link without fbexternal (facebook photo), we are stuck here !: enter image description here

Code prototype:

 if attachment: image_url = attachment.media[0].src if image_url: m = image_url.photo.images if m: if m.src == image_url: image_width = m.width image_height = m.height else: #no dimensions info if host by fbexternal: #extract parameter w and h from https://fbexternal-a.akamaihd.net/safe_image.php?d=AQBhfbzbNudc_SE8&w=130&h=130&url=http%3A%2F%2F image_width = 130 image_height = 130 else: Stuck here, very hard to get extract photo id based on this url, a lot of work! 

In conclusion, I highly recommend that you get the width and height of the image after uploading the photo. For example, PHP has a getimagesize function, and python has a Python Imaging Library (PIL).

+1
source

I'm not sure if there is an easier way to get the width and height you need, but here is a sure but curious long way to go.

Taking your example, the identifier that you see for the first image “20531316728_10151883063741729” is not really an identifier for the image. This is for the message in which the image is located.

What you can do is request for this postID

http://developers.facebook.com/tools/explorer?method=GET&path=20531316728_10151883063741729

then it will display the image object_id 457846347622804 (do a search and you will understand what I mean). now you are requesting this image id and you will have width and height.

http://developers.facebook.com/tools/explorer?method=GET&path=457846347622804

From now on, you should be able to get the ratio you need.

If anyone has an elegant way to achieve this, I would also like to know.

0
source

All Articles