Search code examples
phpinstagram-api

Can't play video from instagram API response


I get this response from the PHP code using the API: https://www.instagram.com/explore/tags/user_defined_tag_name.

Now, I am trying to play the video in browser by using the URL from "display_src". However, i was not able to play it.

Any help will be appreciated!!

"thumbnail_src": "https:\/\/scontent.cdninstagram.com\/t51.2885-15\/e15\/c157.0.406.406\/15035073_1165170080216101_8101167348074938368_n.jpg?ig_cache_key=MTM4OTY2NjA5Mjc3OTU2NjMxNg%3D%3D.2.c",
                    "is_video": true,
                    "id": "1389666092779566316",
                    "display_src": "https:\/\/scontent.cdninstagram.com\/t51.2885-15\/s640x640\/e15\/15035073_1165170080216101_8101167348074938368_n.jpg?ig_cache_key=MTM4OTY2NjA5Mjc3OTU2NjMxNg%3D%3D.2",
                    "video_views": 6

Solution

  • According to the Instagram API doc, response will be like something below:

     "type": "video",
        "videos": {
                    "low_resolution": {
                        "url": "http://distilleryvesper9-13.ak.instagram.com/090d06dad9cd11e2aa0912313817975d_102.mp4",
                        "width": 480,
                        "height": 480
                    },
                    "standard_resolution": {
                        "url": "http://distilleryvesper9-13.ak.instagram.com/090d06dad9cd11e2aa0912313817975d_101.mp4",
                        "width": 640,
                        "height": 640
                    }
    

    Now if you save the response in $result

    <?php foreach ($result as $post) {
        if ($post->type == "image") { ?>
            <!-- Go for your image option -->
        <?php } 
    
        else { ?>
           <!-- video will be in $post->videos->standard_resolution->url key -->
        <?}
    } ?>