使用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结果:

解决步骤
- 统一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}") - 核对令牌权限:确保访问令牌包含
instagram_basic、pages_show_list、instagram_content_publish等必要权限,且令牌状态为有效(未过期、未被撤销)。 - 检查令牌格式:确认
ACCESS_TOKEN无多余空格、转义字符,直接使用Token Debugger中显示的完整有效令牌替换"token"。 - 验证用户ID:确认通过GET请求获取的
user_id是Instagram业务账号ID,而非个人用户ID,可在Token Debugger中核对令牌关联的账号信息。
内容的提问来源于stack exchange,提问作者vate
相关产品推荐
相关产品推荐

