user645579
user645579

Reputation:

Trouble with Twitter API using Python

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: enter image description here

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

Upvotes: 1

Views: 4351

Answers (3)

Matthew A. Russell
Matthew A. Russell

Reputation: 1

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.

Upvotes: 0

vy32
vy32

Reputation: 29655

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.

Upvotes: 2

samplebias
samplebias

Reputation: 37909

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'}, ...

Upvotes: 0

Related Questions