Search code examples
phpjsonparsinginstagraminstagram-api

Instagram API - Retrieve Only Videos


I need to retrieve ONLY videos tagged with a certain hashtag. I understand there isn't any way to retrieve only videos, but how could I parse through the JSON object I get back and only use the videos? I've been examining the array and I don't see any field that I could reliably use to determine if the result was a video or photo (ie, something like: ['type'] => 'image' would be really helpful, if it existed).

To be fair, this is a huge array, and I could be missing something obvious.

So: is there any way to parse through all the results and only use the videos? (I'd then put those results in a new array to actually use)

Thanks in advance!


Solution

  • Apparently I WAS missing it! Not only is there a way to do it, but it's exactly the hypothetical way I asked about. There's a field called ['type'] which can equal 'video' or 'image' (or others, possibly).

    So, for anyone looking to do the same thing as me, you might want to write something like:

    foreach ($obj->data as $post) {
    
        // check media type and skip this result if 
        $media_type = $post->type;
    
        if($media_type != 'video'){
            continue;
        }
    }