Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 945
Peregrine Avatar asked Dec 22 '25 02:12

Peregrine


1 Answers

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;
    }
}
like image 169
Peregrine Avatar answered Dec 24 '25 17:12

Peregrine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!