I'm using Graph API to get the wall post of a fan page.
I noticed the Facebook iOS app itself is able to determine the exact ratio for its placeholder.
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 contains no information of the pictures' dimension in the API response, which I'd like to have a correct placeholder size with my custom client like the Facebook iOS app.
I tried adding /facebook/feed?fields=picture,width,height but no luck in retrieving the corresponding information.
Is there a possible way to retrieve the pictures's height and width param from the API itself?
No, API doesn't return ALL picture's dimensions based on post feed from /page_id/feed or stream table.
I mentioned all because, what you can do is:
SELECT post_id, created_time, actor_id, attachment, message FROM stream WHERE source_id=PAGE_ID AND created_time<now() LIMIT 50
If the post type is photo:
If the post type is video:
If the post type is link start with fbexternal (extract parameter w and h):
If the post type is link without fbexternal (facebook photo), we stuck 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 you to get image width and height after download photo. For example, PHP have getimagesize function and python have Python Imaging Library (PIL).
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