我正在尝试使用 Buffer 这个服务通过 API 在 Facebook 上发布帖子。
这是我的代码:
params = {
'profile_ids': ids,
'text': "text",
'access_token': access_token
}
r = requests.post('https://api.bufferapp.com/1/updates/create.json', params=params)
print r.json()
print(r.url)
但是当我运行它时,它会打印出以下消息:
{"success":false,"message":"Please select at least one account to post from.","code":1004}
This is the URL used to make the request:
https://api.bufferapp.com/1/updates/create.json?access_token=ACCESS_TOKEN&text=TEXT&profile_ids=LIST_WITH_PROFILE_IDS
我确保 ID 是正确的,并且我手动和通过 API 获取它,但仍然收到相同的消息。
唯一需要的参数是 profile_ids,它应该是一个数组。以下是他们网站上有关发布帖子(“更新”)的文档:https://buffer.com/developers/api/updates
我在这里做错了什么?
最佳答案
API 似乎需要 post
请求负载中的数据,而不是 URL 参数。
使用数据
,而不是参数
。
r = requests.post('https://api.bufferapp.com/1/updates/create.json', data=params)
# -------------------------------------------------------------------^^^^ here
关于Python API Post请求URL返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57597524/