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

问题描述 投票:1回答:1

我正在尝试使用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状态代码。什么是正确的方法?

请帮助

python json api twitter python-requests
1个回答
0
投票

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

embResp = requests.get(embReqUrl)
print(embResp.status_code)  
print(embResp.json())
© www.soinside.com 2019 - 2024. All rights reserved.