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

使用Python调用Instagram Graph API发布故事时user_tags参数报错

解决Instagram Graph API发布故事时user_tags参数错误的问题

问题原因

出现(#100) Param user_tags[0] must be a JSON object错误的核心原因是参数传递格式不符合API要求:

  • 直接传递Python列表时,requests.post的data参数会把列表拆分为多个表单字段,而非API期望的JSON格式字符串。
  • 单独对userTags做json.dumps后仍报错,是因为仅序列化子参数但未正确设置整个请求的Content-Type,导致API无法识别JSON格式。

解决方案

以下两种方式均可正确传递参数:

方式1:使用requests的json参数自动处理序列化

import requests

userTags = [{'username': 'testing', 'x': 0.5, 'y': 0.2}] 
instaObj = { 
    'access_token': accessToken, 
    'video_url': reelsUrl, 
    'user_tags': userTags
}
# 用json参数发送请求,requests会自动将字典序列化为JSON并设置Content-Type为application/json
res = requests.post(instaPost, json=instaObj)

方式2:手动序列化整个请求体并设置请求头

import requests
import json

userTags = [{'username': 'testing', 'x': 0.5, 'y': 0.2}] 
instaObj = { 
    'access_token': accessToken, 
    'video_url': reelsUrl, 
    'user_tags': userTags
}
# 序列化整个请求体为JSON字符串
payload = json.dumps(instaObj)
headers = {'Content-Type': 'application/json'}
res = requests.post(instaPost, data=payload, headers=headers)

关键说明

Instagram Graph API要求user_tags是包含标签对象的JSON数组,通过上述两种方式传递,能确保请求体以JSON格式发送,让API正确解析user_tags参数。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 15:52:16