ptwobrussell / Recipes-for-Mining-Twitter

Adaptations and Extensions of Twitter-Related Examples from Mining the Social Web
http://amzn.to/d1Ci8A
382 stars 145 forks source link

API version error #9

Closed wandeg closed 11 years ago

wandeg commented 11 years ago

Hi, when I run the code for the trends recipe I get this error: "errors": [{"message": "The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.", "code": 68. Kindly advise

ptwobrussell commented 11 years ago

Which file in this repository are you trying to run? AFAIK, all of the code here has been updated to reflect the v1.1 API. (The text of the book, if you are typing it in or copying/pasting from the page itself, will not be updated. Download the code from this repository and use it.)

Let me know if this works for you.

wandeg commented 11 years ago

The code works okay on Linux but has the error on Windows. Perhaps it's a configuration issue or something to do with the Twitter package in the Enthought Canopy distribution.

wandeg commented 11 years ago

Oh and the code that works is the one for Chapter 1 of Mining The Social Web 1st edition

ptwobrussell commented 11 years ago

Forgive me, but I'm having trouble understanding your problem. Can you answer my question about whether or not you are typing the code out of the book or using code that is in one of the source code repositories? Better yet, can you copy/paste in your exact code and your exact error messages here into this ticket? That would really help me to get a better handle on the issue that you are reporting. Thank you.

wandeg commented 11 years ago

Sorry about the confusion. I'm using code from the repositories of 21 recipes for mining twitter and mining the social web 1st edition. I did not type any code. There are scripts for getting twitter trends in both repositories. The script in mining the social web (chapter1.py) works well without any errors. However the script in 21 recipes for mining twitter (recipe__get_trending_topics.py) gives me an error.Here is the code:

-- coding: utf-8 --

import json import twitter from recipe__oauth_login import oauth_login

t = oauth_login() WORLD_WOE_ID = 1 # The Yahoo! Where On Earth ID for the entire world world_trends = t.trends.place(_id=WORLD_WOE_ID) # get back a callable

call the callable and iterate through the trends returned

print json.dumps(world_trends, indent=1)

This is the error

TwitterHTTPError: Twitter sent status 410 for URL: 1/trends/place.json using parameters: (_id=1&oauth_consumerkey=****&oauthnonce=**_&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1378068187&oauth_token__&oauth_version=1.0&oauthsignature=*****) details: {"errors": [{"message": "The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.", "code": 68}]}

ptwobrussell commented 11 years ago

Thanks for the clarification.

I think that the code that you are pasting in above should be fine itself. What I think is happening is that the version of the "twitter" package that you are importing on your Windows setup is different (older) than the one on your Linux setup. The reason I think this is because an older version of the twitter package used the v1 API of Twitter as the default and it's not too long ago that it upgraded the default to be v1.1.

My initial recommendation would be to pip install twitter on your Windows setup and make sure that it installs the latest version, which should be v1.10 - https://pypi.python.org/pypi/twitter/1.10.0 - Unfortunately, I have no experience with the details of how Enthought Canopy handles dependencies, but I would imagine it should be fairly straight forward

If you are feeling lazy, however, you might be able to get by, however, by just adding an api_version='1.1' keyword parameter to your Twitter constructor that's inside of recipe__oauth_login.py like this:

twitter.Twitter(api_version='1.1', auth=twitter.oauth.OAuth(access_token, access_token_secret,
                           consumer_key, consumer_secret))

A final word of advice would be to get on board with the codebase for the 2nd Edition of the book, which is where all future development is happening. It even comes with a virtual machine that helps you to totally sidestep all of these configuration management related issues regardless of your platform. A few relevant links that you might find useful:

I hope this helps. I'll leave it to you to comment back or close the issue. Let me know how it goes...

wandeg commented 11 years ago

I tried the code on Linux and it worked so I'm guessing it most probably has to do with the Enthought Canopy package. Thanks for the help.