pythonfacebook-graph-apioauthinstagram-apiinstagram-graph-api

Instagram API - Invalid OAuth access token


I am trying to use the Instagram API with python requests. It works fine with Get requests, however when I try to use it with a Post request, such as trying to publish an image, I get the following error: Invalid OAuth access token - Cannot parse access token', 'type': 'OAuthException', 'code': 190, 'fbtrace_id': 'AZQBd4alFLJx1fGo5yOrxmQ'.

This is my code:

import requests

ACCESS_TOKEN = "token"

user_id_page = requests.get(f"https://graph.instagram.com/v22.0/me?fields=user_id&access_token={ACCESS_TOKEN}")
user_id = user_id_page.json()["user_id"]


post_id = requests.post(f"https://graph.facebook.com/v22.0/{user_id}/media?image_url=https://example.com/image.jpg&access_token={ACCESS_TOKEN}")
print(post_id.json())

My instagram page is set up as a professional creator account. I am using the Instagram API with Instagram login workflow. I tried to renew my access token with no results. I checked with Facebook Access token debugger and got the following results: enter image description here

Thank you for any help.


Solution

  • The problem was: instead of

    https://graph.facebook.com/v22.0...
    
    

    It should have been:

    https://graph.instagram.com/v22.0...