本文介绍了Instagram Graph API:媒体缩略图网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个商业帐户中使用了Instagram Graph API,几乎所有东西都运行良好.我已经创建了Facebook SDK的WordPress端口,并且检索媒体项的函数如下所示(在类的一部分中,$fb对象已经使用类构造函数中的default_access_token进行了身份验证):

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();
    }
}

我所请求的字段是:media_urlcaption thumbnail_url permalink. API使用除thumbnail_url:

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) "..."
}

我使用图形API资源管理器得到了相同的响应,这使我认为与我的应用相关的东西,可能是权限(当前为manage_pagesinstagram_basic),特殊设置或错误(我认为不是,但以防万一...).

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...).

我想念什么?

推荐答案

类似于 thumbnail_url仅在视频IG Media对象上可用.我的解决方案是使用PHP处理图像以生成调整大小的媒体对象版本并将其缓存,这样我就不必在每次请求时都重新生成它们.

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.

这篇关于Instagram Graph API:媒体缩略图网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 18:18