Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram Graph API: Media Thumbnail URL

I'm using the Instagram Graph API in a business account, and almost everything works just fine. I have created a WordPress port of the Facebook SDK, and the function that retrieves the media items looks like this (part of a class, the $fb object is already authenticated using the default_access_token in the class constructor):

public function get_media( $business_account_id = '', $limit = 15 ) {
    $limit = absint( $limit );

    try {
        $response = $this->fb->get( "/{$business_account_id}?fields=media.limit({$limit}){media_url,caption,thumbnail_url,permalink}" );
        return $response->getDecodedBody();
    } catch ( \Facebook\Exceptions\FacebookResponseException $e ) {
        return $e->getMessage();
    } catch ( \Facebook\Exceptions\FacebookSDKException $e ) {
        return $e->getMessage();
    }
}

The fields I'm requesting, as you can see, are: media_url, caption, thumbnail_url and permalink. The API responds with all the fields except for thumbnail_url:

array(2) {
    ["media"]=>
    array(2) {
        ["data"]=>
        array(15) {
            [0]=>
            array(4) {
                ["media_url"]=>
                string(91) "https://scontent.xx.fbcdn.net/..."
                ["caption"]=>
                string(356) "[...]"
                ["permalink"]=>
                string(40) "https://www.instagram.com/p/.../"
                ["id"]=>
                string(17) "..."
            }
            ...
        }
        ["paging"]=>
        array(2) {
            ["cursors"]=>
            array(2) {
                ["before"]=>
                string(123) "..."
                ["after"]=>
                string(122) "..."
            }
            ["next"]=>
            string(438) "https://graph.facebook.com/v2.10/..."
        }
    }
    ["id"]=>
    string(17) "..."
}

I get the same response using the Graph API Explorer, which makes me think is something related to my app, maybe permissions (currently manage_pages and instagram_basic), a special setting or a bug (I don't think so, but just in case...).

What am I missing?

like image 915
Mithc Avatar asked Sep 13 '17 21:09

Mithc


1 Answers

Update 2021

The docs have been updated and the old link doesn't work anymore; here's the new link:

https://developers.facebook.com/docs/instagram-basic-display-api/reference/media/#fields

The wording has been updated to indicate that the thumbnail_url field is only available on VIDEO Media.


Original Answer

Looks like the thumbnail_url is available on video IG Media objects only. My solution is to process the images with PHP to generate resized versions of the media objects and cache them so I don't have the regenerate them on every request.

like image 168
Mithc Avatar answered Nov 02 '22 01:11

Mithc