Instagram基本API:是否可以在一个查询中从“ CAROUSEL_ALBUM”获取media_url?

时间:2019-11-06 14:51:28

标签: facebook-graph-api instagram instagram-api instagram-graph-api

如果您正在阅读this,将会读到可以将children添加到fields查询参数中。这意味着,如果您使用的媒体类型为"CAROUSEL_ALBUM",您还将获得图像的ID。

示例CURL:

https://graph.instagram.com/me?access_token=<mytoken>&fields=id,media_type,media_url,children

结果:

...
     "id": "some-id",
     "media_type": "CAROUSEL_ALBUM",
     "media_url": "some-url",
     "children": {
        "data": [
           {
              "id": "another-id"
           },
           {
              "id": "other-id"
           }
        ]
     }
...

是否可以在儿童数据中添加media_url?我真的不想循环获取所有内容...

2 个答案:

答案 0 :(得分:5)

@Mecha我是为PHP编写的,但也许您可以阅读


    /**
     * Fetches media from the user
     *
     */
    public function fetchUserMedia(array $options, int $limit = 24): object
    {
        $query = http_build_query(array_merge([
            'limit' => $limit,
            'fields' => 'username,caption,id,media_type,media_url,thumbnail_url,children{media_url,thumbnail_url}',
            'access_token' => $this->token
        ], $options));


        return json_decode((string) ($this->client->get("https://graph.instagram.com/me/media?{$query}"))->getBody());
    }

一个输出示例如下:

{
          "caption": "I\u2018m addicted to chia pudding, how about you? \ud83d\ude0d Layers of zingy lemon vanilla chia pudding, mango thyme infused coconut yoghurt and juicy fresh mango roses. \ud83e\udd24\nMade by \u0040addictedtodates \ud83c\udf4b\u2063\u2063\n\u2063\u2063\u2800\nAND now to our tagged picture of today \ud83d\ude0b\ud83d\ude0b Swipe left to see \u0040smoothie_yumm\u2019s coconut vanilla smoothie bowl topped with turmeric chia pudding \ud83e\udd29\n\u2800\nYou can find the recipe on her page \ud83d\udc9b\n\u2800\n\ud83c\udf31 Tag #avidofood or\u00a0\u0040avidofood\u00a0to be featured in the future!\n\u2800\n\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\n#vegan #veganfood #veganfoodie #veganfoodshare #vegatarisch #veganpasta #vegandinner #veganeats #healthyfood #plantbased #plantbasedfood #veganpower #plantbaseddiet #veganiseasy #whatveganseat #forksoverknives #vegetarianrecipes #veganinspo #vegetarian #veganism #veganmeals #veganlife #veganlifestyle #veganlove #veganmealprep #veganrecipes #veganhealth #veganlunch",
          "id": "18039820117203997",
          "media_type": "CAROUSEL_ALBUM",
          "media_url": "https://scontent.xx.fbcdn.net/v/t51.2885-15/71511404_203552310658678_3865693276191599368_n.jpg?_nc_cat=100&_nc_oc=AQlet8stFGS32TTdBhXT4NNfpzd8eNq7oI0xilix4qyiVvt50avuk6RVotMgM-BUptmCrsVwLCGkPCc-sL7b-eAy&_nc_ht=scontent.xx&oh=f1a700b4d021d2d577d54cd74f4838fa&oe=5E534677",
          "permalink": "https://www.instagram.com/p/B3-XRMOIWPW/",
          "username": "avidofood",
          "children": {
             "data": [
                {
                   "media_url": "https://scontent.xx.fbcdn.net/v/t51.2885-15/71511404_203552310658678_3865693276191599368_n.jpg?_nc_cat=100&_nc_oc=AQlet8stFGS32TTdBhXT4NNfpzd8eNq7oI0xilix4qyiVvt50avuk6RVotMgM-BUptmCrsVwLCGkPCc-sL7b-eAy&_nc_ht=scontent.xx&oh=f1a700b4d021d2d577d54cd74f4838fa&oe=5E534677",
                   "id": "18041124712207922"
                },
                {
                   "media_url": "https://scontent.xx.fbcdn.net/v/t51.2885-15/72483636_1251439178368296_6758852942587086206_n.jpg?_nc_cat=109&_nc_oc=AQmVrktP2g7Z72WifVdu4z17OzwM7ZNFLln1e1ZQxjdUi-j79Ttf-i840mjYkOb-TW3Dwm39Gyoe3EefxwB7UydW&_nc_ht=scontent.xx&oh=a07d3f51aa5eb5eb30697c4ad25d4e35&oe=5E60AEC3",
                   "id": "17851162897631131"
                }
             ]
          }

答案 1 :(得分:1)

您只需要将字段嵌套在子查询参数中

/media?fields=id,media_url,children{media_url}&access_token=