php - Instagram video fetching not working?

686

I am trying to show video from instagram,but its not working for me.I am giving the code below:

<?php foreach ($result->data as $post): ?>
        <!-- Renders images. @Options (thumbnail,low_resoulution, high_resolution) -->
        <a class="group" rel="group1" href="<?= $post->images->standard_resolution->url ?>"><img src="<?= $post->images->thumbnail->url ?>"></a>
    <?php endforeach ?>

Above code is performing well for image,any idea how to display video.If possible than suggest me about pagination also?

245

Answer

Solution:

According to the doc of the API you can check if the media is an image or a video.

Then just check it before create your HTML, somethin like this should work:

<?php foreach ($result->data as $post) {
    if ($post->type == "image") { ?>
        <!-- Renders images. @Options (thumbnail,low_resoulution, high_resolution) -->
        <a class="group" rel="group1" href="<?php $post->images->standard_resolution->url ?>"><img src="<?= $post->images->thumbnail->url ?>"></a>
    <?php } 

    else { ?>
       <video width="640" height="480" controls="controls">
       <source src="<?= $post->videos->standard_resolution->url ?>" type="video/mp4">
       </video>


    <?}
} ?>

People are also looking for solutions to the problem: navigation - php nav bar active

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.