0

我正在阅读《龙卷风简介》一书。我正在尝试使用 tornado.httpclient 访问 twitter api。在他们的示例中,他们使用不受支持的旧 v1 搜索 api。v1.1 支持的需要 oauth 身份验证。

就我而言,我拥有所有可用的 oauth 信息(例如,应用程序和用户的令牌和密码)。但是,我无法弄清楚如何将它们与当前的 fetch 调用结合起来:

response = client.fetch("https://api.twitter.com/1.1/search/tweets.json?q=football&result_type=recent&rpp=100")

问题是如何更改此调用以添加 oauth 支持。我对requests 库做了类似的事情,我只需将 OAuth1 对象添加到调用中。

ua = OAuth1(client_key=TWITTER_CONSUMER_KEY,
            client_secret=TWITTER_CONSUMER_SECRET, 
            resource_owner_key=token,
            reource_owner_secret=secret,signature_type='auth_header')


requests.get("https://api.twitter.com/1.1/search/tweets.json",
              auth=ua,
              params=dict(q="football",result_type="recent",rpp=100))

我可以做一些类似于 tornado.httpclient 中的请求库的事情吗?谢谢。

4

1 回答 1

0

tornado.httpclient模块不支持 OAuth,但该tornado.auth模块支持。子类化tornado.auth.TwitterMixin并使用它的twitter_request方法。

于 2013-10-11T13:53:34.693 回答