PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 26, 2022

[FIXED] Instagram Graph API: Media Thumbnail URL

 February 26, 2022     facebook-graph-api, facebook-php-sdk, instagram-api     No comments   

Issue

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?


Solution

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.



Answered By - Mithc
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing