How to get video from Instagram public access API?

✔ Recommended Answer

When you make above API call it would return code in it. looks something like this: BWhyIhRDBCw

Whenever your media nodes has "is_video": true you can make following call:

https://www.instagram.com/p/{code}/?__a=1

for e.g.,https://www.instagram.com/p/BWhyIhRDBCw/?__a=1

This would return another json. which will have video_url you are looking for.

sample:

"video_url": "https://scontent-bom1-1.cdninstagram.com/vp/437699b67172f450331fa732f0777b18/5A7FE0A0/t50.2886-16/20138822_486349355081174_1539674401849475072_n.mp4",

Source: stackoverflow.com

Answered By: enator

Method #2

To get a video from Instagram using the public access API, you can use the Instagram Graph API. Here's an example of how to get a video from Instagram using PHP:

  1. First, you'll need to obtain an access token for the Instagram Graph API. You can do this by following the instructions in the Instagram Graph API documentation.

  2. Once you have an access token, you can use it to make a request to the Instagram Graph API to get the video. The API endpoint for getting a video is:

    bash
    https://graph.instagram.com/{media-id}?fields=id,caption,media_type,media_url,thumbnail_url&access_token={access-token}

    Replace {media-id} with the ID of the video you want to get, and {access-token} with your access token.

  3. To make the request using PHP, you can use the file_get_contents() function to fetch the JSON response from the API endpoint, and then use the json_decode() function to convert the JSON string into a PHP object. Here's an example:

    php
    $mediaId = '1234567890'; // Replace with the ID of the video you want to get $accessToken = 'YOUR_ACCESS_TOKEN'; // Replace with your access token $apiUrl = "https://graph.instagram.com/{$mediaId}?fields=id,caption,media_type,media_url,thumbnail_url&access_token={$accessToken}"; $json = file_get_contents($apiUrl); $data = json_decode($json); $videoUrl = $data->media_url;

    This will fetch the JSON response from the API endpoint and convert it to a PHP object. The media_url property of the object will contain the URL of the video.

  4. To display the video in your HTML page, you can use the <video> tag and set the src attribute to the URL of the video. Here's an example:

    html
    <video controls> <source src="<?php echo $videoUrl; ?>" type="video/mp4"> </video>

    This will display the video in a HTML5 video player with playback controls.

Note that the Instagram Graph API has rate limits and other usage restrictions. Make sure to read the API documentation and comply with the terms of use.

Comments

Most Popular

Remove Unicode Zero Width Space PHP

PhpStorm, return value is expected to be 'A', 'object' returned

Laravel file upload returns forbidden 403, file permission is 700 not 755