开发者

Trouble with Twitter API using Python

开发者 https://www.devze.com 2023-03-05 14:17 出处:网络
I\'m having some trouble in this python code: import twitter 开发者_如何转开发twitter_search = twitter.Twitter(domain=\"search.twitter.com\")

I'm having some trouble in this python code:

import twitter
开发者_如何转开发twitter_search = twitter.Twitter(domain="search.twitter.com")
trends = twitter_search.trends()

The error (404 page not found) is right here:

Trouble with Twitter API using Python

I'm using this package: http://github.com/sixohsix/twitter


Because of the new API change, you need to use this program:

import twitter
twitter_api = twitter.Twitter(domain="api.twitter.com", api_version='1')
WORLD_WOE_ID = 1
world_trends = twitter_api.trends._(WORLD_WOE_ID) 
trends = world_trends()
print [trend['name'] for trend in trends[0]['trends']]

This is based, in part, on the book errata website.


According to the Twitter API documentation for the trends call the domain should be api.twitter.com:

import twitter
twitter_search = twitter.Twitter(domain="api.twitter.com")
print twitter_search.trends()

{u'trends': [{u'url': u'http://search.twitter.com/search?q=%23weedcommandments', 
 u'name': u'#weedcommandments'}, ...


You may want to checkout the updated IPython Notebook for Chapter 1 of Mining the Social Web that shows an updated example for this workflow and API call as well as a little bit of other context that is compatible with Twitter's v1.1 API. See http://nbviewer.ipython.org/urls/raw.github.com/ptwobrussell/Mining-the-Social-Web/master/ipython_notebooks/Chapter1.ipynb for a read-only version of the notebook.

0

精彩评论

暂无评论...
验证码 换一张
取 消