Instagram API - Getting invalid media id with video shortcode

北战南征 提交于 2020-01-07 06:34:06

问题


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.


回答1:


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.




回答2:


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)


来源:https://stackoverflow.com/questions/43733285/instagram-api-getting-invalid-media-id-with-video-shortcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!