Python API Post请求URL返回错误

标签 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

我在这里做错了什么?

最佳答案

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/

相关文章:

python - 在 google appengine 上使用 django 使用数据初始化表单

python - subprocess.run() 产生与手动输入不同的结果

python - 将列表函数应用于 itertools.groupby 中的嵌套生成器

python - Python 是否优化尾递归?

api - 为第 3 方服务的客户端设计 API

web-applications - 网站和网络应用程序有什么区别?

python - 如何从 Google Plus 企业列表中提取类别?

c++ - mfc c++ 中是否存在用于 URL 编码的 API?

javascript - 以编程方式在后台打开一个新的浏览器选项卡

iphone - 我可以提供用于Web应用程序的iPhone主屏幕快捷方式的图标吗?