Kerim Emurla
Kerim Emurla

Reputation: 1151

Instagram API - Getting invalid media id with video shortcode

I'm using the /media/shortcode/shortcode endpoint of instagram to get information about a certain media with a shortcode.

https://www.instagram.com/developer/endpoints/media/#get_media_by_shortcode

The problem is when I pass a photo's shortcode to the endpoint everything works fine and I get the result I'm expecting from Instagram, however, when I pass a video's shortcode to that endpoint, the api returns the following:

{
  "meta": {
    "code": 400,
    "error_type": "APINotFoundError",
    "error_message": "invalid media id"
  }
}

Which does not make a lot of sense to me since the given endpoint should work just fine with videos.

Upvotes: 0

Views: 1504

Answers (2)

Shubham Gupta
Shubham Gupta

Reputation: 81

The best and the easiest way to get the media info, either being photo or video is by calling this url (GET method) Insta Fetch Media URL

Sample code written in Python.

import requests, json
def get_media_id(image_url):


     url = "https://api.instagram.com/oembed/"

     querystring = {"callback": "", "url": image_url}

     headers = {
        'cache-control': "no-cache"
     }

     response = requests.request("GET", url, headers=headers, params=querystring)
     return json.loads(response.text)

Upvotes: 0

abiogenesisnow
abiogenesisnow

Reputation: 61

I was running into this issue too---the Instagram documentation is not super clear, but this is because of the limitations of Sandbox mode.

To help you develop and test your app, the users and media available in Sandbox mode are real Instagram data (i.e. what is normally visible in the Instagram app), but with the following conditions:

  • Apps in sandbox are restricted to 10 users
  • Data is restricted to the 10 users and the 20 most recent media from each of those users
  • Reduced API rate limits

From https://www.instagram.com/developer/sandbox/.

TLDR you'll need to get your app approved to have your other API calls work.

Upvotes: 2

Related Questions