Twitter: Difference between revisions

m
Changed name of tab from "API Keys" to "Keys and Access Tokens" as it is now named
imported>Konarkmodi
imported>Clarkkarenl
m (Changed name of tab from "API Keys" to "Keys and Access Tokens" as it is now named)
 
(10 intermediate revisions by 5 users not shown)
Line 1:
[[File:Twitter.png|right|300px]]
 
''Note: as of July/August 2013, this page needs to be updated to reflect Twitter's switch to its 1.1 API. See [http://openhatch.org/bugs/issue867 this bug for updates]. Sorry!''
 
== Project ==
Line 24 ⟶ 22:
<pre>pip install httplib2 simplejson oauth2 python-twitter</pre>
 
=== Register a "Twitter application" on Twitter.com ===
The python-twitter library now only supports oAuth authentication as the Twitter devs have indicated that OAuth is the only method that will be supported moving forward. So make sure in order to use the Twitter App you have the following with you:
 
* consumer_key
The python-twitter library now only supports oAuth authentication as the Twitter devs have indicated that OAuth is the only method that will be supported moving forward. So make sureyou in orderneed to useregister theas a Twitter Appdeveloper. youThis haveis thefairly followingeasy withand you:free of cost.
* consumer_secret
* access_token_key
* access_token_secret
 
Registration Process:
* Log in to the Twitter Developerdeveloper Sitesite [https://dev.twitter.com/apps/new] with your regular Twitter username and password.
* Create a new Twitter application. For the fields, try these suggestions:
* 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.
** '''Name''': My sample Twitter app
* Write down the below credentials Twitter just created for your application (you'll need them later on): Consumer key Consumer secret
** '''Description''': My description
* 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.
** '''Website''': https://openhatch.org/wiki/Twitter
** ''Callback URL''': (leave this blank)
** Now you can click to '''Create your Twitter application'''. You should proceed to the app information page.
 
 
(If you run into problems, take note: The website URL has to start with http or https. You don't need to specify Callback URL.)
 
Now, make the Twitter application able to post to your Twitter profile. To do that:
 
* Start at the app information page. (The '''Details''' tab should be selected.)
* Switch to the '''Permissions''' tab.
* Scroll down to '''Access''' and choose '''Read, and Write'''.
* Click '''Update settings'''.
 
 
Now, you need to permit yourself to use that app. To do that:
 
* Start at the app information page. (Make sure you are on the '''Details''' tab.)
* Switch to the '''Keys and Access Tokens''' tab.
* At the endbottom of the page, under the "Your access token" section, there is a button - "Create my Accessaccess Tokentoken" , 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 torefresh the "OAuthpage tool"and tabyou'll onsee the same page andthat all your app's credentials will be listed and are to be kept confidential.
* Write down the below credentials Twitter just created for your application, (you'llor needjust themkeep laterthe on):browser Consumertab key Consumer secretopen:
** API key
** API secret
** Access token
** Access token secret
 
Once you have the above mentioned details, you can use the skeleton code shared below.
Line 65 ⟶ 86:
# Read through the <code>search</code> function in <code>twitter_functions.py</code>.
# Trace through the logic in <code>twitter_api.py</code> that turns the <code>--search</code> command line option into a call to <code>search</code>.
# Find <code>GetSearch</code> in the TwitterPython librarywrapper codefor Twitter at httphttps://code.googlegithub.com/pbear/python-twitter/sourceblob/browsemaster/twitter/api.py. What other options could we have passed to <code>GetSearch</code>?
 
<b>Check your understanding</b>: What does <code>api.GetSearch</code> return?
 
 
=== 2. Read through and understand <code>trendingTopics</code> ===
Line 75 ⟶ 95:
# Read through the <code>trendingTopics</code> function in <code>twitter_functions.py</code>.
# Trace through the logic in <code>twitter_api.py</code> that turns the <code>--trending-topics</code> command line option into a call to <code>search</code>.
# Find <code>GetTrendsWoeid</code> in the TwitterPython librarywrapper codefor Twitter at https://github.com/bear/python-twitter/blob/master/twitter/api.py. How many trending topics does that method return?
 
<b>Check your understanding</b>: What are the differences between the <code>optparse</code> logic for <code>--search</code> and <code>--trending-topics</code>?
Line 147 ⟶ 167:
Extend <code>trendingTopics</code> so that a Yahoo! Where On Earth ID (WOEID) can be specified on the command line and trending topics for that location will be displayed instead of using the hardcoded <code>BOSTON_WOEID</code> to only display results for Boston.
 
You can look up WOEIDs by location at http://sigizmundwoeid.info/woeidinforosselliot.co.nz/
 
 
===Congratulations!===
Anonymous user