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:
I'm using this package: http://github.com/sixohsix/twitter
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'}, ...
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.
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.