我正在尝试使用 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/