【问题标题】:How to call Twitter oEmbed API using python requests?如何使用 python 请求调用 Twitter oEmbed API?
【发布时间】:2020-05-11 15:20:26
【问题描述】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-10
      • 2019-11-16
      • 1970-01-01
      • 2021-03-03
      • 2012-04-22
      • 2018-10-10
      • 2014-09-29
      相关资源
      最近更新 更多