You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python调用Instagram API发布内容时遇OAuth令牌无效错误求助

解决Instagram API POST请求OAuthException(190)令牌解析错误

问题现象

  • 使用Python requests调用Instagram API,GET请求(如获取user_id)正常执行
  • 发起POST请求发布图片时,返回错误:

    Invalid OAuth access token - Cannot parse access token
    错误类型:OAuthException,代码190,fbtrace_id: AZQBd4alFLJx1fGo5yOrxmQ

复现代码

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())

已排查情况

  • Instagram账号为专业创作者账号,采用Instagram登录流程调用API
  • 已尝试刷新访问令牌,无效
  • Facebook Access Token Debugger结果:
    Facebook Access Token Debugger结果

解决步骤

  1. 统一API端点:GET请求使用graph.instagram.com,但POST请求误用了graph.facebook.com,需将POST请求URL改为graph.instagram.com:
    post_id = requests.post(f"https://graph.instagram.com/v22.0/{user_id}/media?image_url=https://example.com/image.jpg&access_token={ACCESS_TOKEN}")
    
  2. 核对令牌权限:确保访问令牌包含instagram_basic、pages_show_list、instagram_content_publish等必要权限,且令牌状态为有效(未过期、未被撤销)。
  3. 检查令牌格式:确认ACCESS_TOKEN无多余空格、转义字符,直接使用Token Debugger中显示的完整有效令牌替换"token"。
  4. 验证用户ID:确认通过GET请求获取的user_id是Instagram业务账号ID,而非个人用户ID,可在Token Debugger中核对令牌关联的账号信息。

内容的提问来源于stack exchange,提问作者vate

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 11:08:25