Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graph API: Retrieving picture dimensions in page feed

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.

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 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?

like image 335
James Tang Avatar asked May 10 '13 04:05

James Tang


1 Answers

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: enter image description here

If the post type is video: enter image description here

If the post type is link start with fbexternal (extract parameter w and h): enter image description here

If the post type is link without fbexternal (facebook photo), we 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 you to get image width and height after download photo. For example, PHP have getimagesize function and python have Python Imaging Library (PIL).

like image 98
林果皞 Avatar answered Oct 21 '22 05:10

林果皞