Talk:Twitter

From OpenHatch wiki

Hi,

I have installed all the dependencies required for the Twitter project. To test the installation when I run :

python twitter_api.py --search=python

I am getting the below error, stack trace :


Traceback (most recent call last):

 File "twitter_api.py", line 44, in <module>
   main(sys.argv[1:])
 File "twitter_api.py", line 35, in main
   twitter_functions.search(opts.search_term)
 File "/home/kutti/OpenHatch projects/twitter/Twitter/twitter_functions.py", line 16, in search
   tweets = api.GetSearch(searchTerm)
 File "/usr/local/lib/python2.6/dist-packages/twitter.py", line 2524, in GetSearch
   data = self._ParseAndCheckTwitter(json)
 File "/usr/local/lib/python2.6/dist-packages/twitter.py", line 4396, in _ParseAndCheckTwitter
   self._CheckForTwitterError(data)
 File "/usr/local/lib/python2.6/dist-packages/twitter.py", line 4421, in _CheckForTwitterError
   raise TwitterError(data['errors'])


I got to know this has something to do with the movement of Twitter API 1 to 1.1. Am I right? Also, still unable to figure out how to solve the same. Could someone help?

Thanks, Divya


Hi Divya! You're right that this needs to be fixed to work with the new Twitter API - see this bug on the OpenHatch bugtracker. Sorry about that! Unfortunately I don't know enough to fix it myself, but you can subscribe to that bug for updates on when it gets fixed. Brittag (talk) 00:39, 7 August 2013 (UTC)

Issue867 resolved

Hi Brittag,

I was able to resolve the issue with help from [1] and few modifications. The Twitter APIs can henceforth be accessed only through "Registered Twitter applications". In the process of the app registration we get what are called Consumer_Key, Consumer_Secret, Access_Token_Key and Access_Token_Secret - all four of which are to be fed into the twitter.Api() method.

Registration Process:

1) Log in to Twitter Developer Site [2] with your regular Twitter username and password.

2) Create a new Twitter application. Few problems I faced during the registration: a)The website URL has to start with http:// b)You don't need to specify Callback URL. If you do any POST actions, you must set access to Read & Write.

3)Write down the below credentials Twitter just created for your application (you'll need them later on): Consumer key Consumer secret

4)At the end of the page there is a button - "Create my Access Token" , click on this to generate the access_token_key and access_token_secret. Once you get the confirmation that your app's access tokens have been created you can go to the "OAuth tool" tab on the same page and all your app's credentials will be listed and are to be kept confidential.

5)Now back to our sources:

In twitter_functions.py, modify the call twitter.Api() to below:

               twitter.Api(consumer_key = '<Consumer key generated above>',
                           consumer_secret = '<Consumer secret generated above>',
                           access_token_key = '<Access token key generated above>',
                           access_token_secret = '<Access token secret generated above>')

Now you should be able to successfully run:

python twitter_api.py --search=Python

and see some tweets containing the word "Python"  :)

I am yet to familiarise myself with the bug tracking system used here @ OpenHatch. So till I can do that, hope this helps.

Cheers --Divya KV (talk) 15:49, 7 August 2013 (UTC)