python - 如何使用 python 请求调用 Twitter oEmbed API?

标签 python json api twitter python-requests

我正在尝试使用 python 的请求库从 twitter oEmbed API 获取 JSON 响应。我尝试传入的推文 ID 是 1221064170248065024。这是我用来向 API 发出请求的代码。

import requests

tweet_id = '463440424141459456'
embReqUrl = 'https://publish.twitter.com/oembedurl=https://twitter.com/Interior/status/'+tweet_id
embResp = requests.post(embReqUrl)

之后,当我使用 embResp.status_code 检查响应的 HTTP 状态时,它给了我一个 405 状态代码。正确的做法是什么?

请帮忙

最佳答案

您使用了 POST 方法,但此 API 需要 GET。

embResp = requests.get(embReqUrl)
print(embResp.status_code)  
print(embResp.json())

关于python - 如何使用 python 请求调用 Twitter oEmbed API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59910984/

相关文章:

django - 配置 Django-oauth-plus 时出错

python - 用于将 3d 数组展平为 pandas df 的内置函数?

python - Python 中列表的极端模式

javascript - 从 AngularJS 访问全局变量

javascript - 如何在 Javascript 中解析/过滤 JSON 文件中的数据

windows - Windows API 是否提供对内核的访问权限,还是比这更复杂?

Python 对 >= 10,000 的数字进行列表比较的效率

python - 用户认证 : prepare vs get_current_user in tornado

asp.net - 如何从 AJAX 调用非静态方法?

Django Rest框架在没有 View 集的情况下执行自定义函数(远程过程调用)