Python API发布请求URL返回错误

时间:2019-08-21 18:40:02

标签: python api web-applications python-requests

我正在尝试使用此服务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

我在这里做什么错了?

1 个答案:

答案 0 :(得分:1)

API似乎期望post请求有效负载中的数据,而不是url参数。

使用data,而不是params

r = requests.post('https://api.bufferapp.com/1/updates/create.json', data=params)
# -------------------------------------------------------------------^^^^ here