5

If you are reading this, you will read that you can add children to the fields query parameter. That means that if you have a media with the type "CAROUSEL_ALBUM" you will get the ids of the images as well.

Example CURL:

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

The result:

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

Is it possible to add media_url to the children's data? I don't really want to fetch everything in a loop...

Philipp Mochine
  • 4,351
  • 10
  • 36
  • 68
  • 5
    Should be possible via Field Expansion. https://developers.facebook.com/docs/instagram-basic-display-api/reference/media/children#reading, https://developers.facebook.com/docs/graph-api/advanced#fieldexpansion – 04FS Nov 06 '19 at 15:02
  • 2
    @04FS love you it worked. You just need to add `children{media_url}` – Philipp Mochine Nov 06 '19 at 15:20
  • @Shadrix I'm trying to achieve the same thing but can't. Could you add an answer to the question, showing the full request and a sample of the response? – Mecha Mar 27 '20 at 14:50
  • @Mecha have a look :) – Philipp Mochine Mar 27 '20 at 15:10

2 Answers2

15

@Mecha I did this for PHP, but maybe you can read this


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

One output example is like this:

{
          "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"
                }
             ]
          }
Philipp Mochine
  • 4,351
  • 10
  • 36
  • 68
  • 1
    Thanks. I'm actually using PHP too. I see now why it didn't work for me. If you include invalid fields in field expansion for `children{...}`, instead of expanding `children.data` the API will instead replace all the main items in the response with their children. Must be a bug in the Graph API. – Mecha Mar 30 '20 at 09:26
  • children{media_url} this part does the trick – almo Nov 25 '22 at 16:00
7

You just need to nest the fields in the children query params

/media?fields=id,media_url,children{media_url}&access_token=
Nelly Cheboi
  • 71
  • 1
  • 2