Created
February 23, 2011 02:01
-
-
Save marcelcaraciolo/839843 to your computer and use it in GitHub Desktop.
A simple Console Twitter API Handler.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = '[email protected]' | |
__version__ = '0.2' | |
import oauth | |
import twitterT | |
import pickle | |
def first_auth(username,consumerKey,consumerSecret): | |
api = twitterT.OAuthApi(consumerKey,consumerSecret) | |
request_token = api.getRequestToken() | |
authorization_url = api.getAuthorizationURL(request_token) | |
print '==== GO TO THIS URL AND GRANT THE ACCESS!! ====' | |
print authorization_url | |
raw_input('Press any key to continue after authorizing this application...') | |
access_token = api.getAccessToken(request_token) | |
access_token = oauth.Token(access_token['oauth_token'], access_token['oauth_token_secret']) | |
output = open(username + '.pk1','wb') | |
pickle.dump(access_token,output) | |
output.close() | |
return access_token | |
def getTwitterApi(username,consumerKey,consumerSecret): | |
try: | |
f = open(username + '.pk1','rb') | |
token = pickle.load(f) | |
except: | |
token = first_auth(username,consumerKey,consumerSecret) | |
api = twitterT.OAuthApi(consumerKey,consumerSecret,token.key,token.secret) | |
return api | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment