Skip to content

Instantly share code, notes, and snippets.

@ashish0x90
Created October 19, 2010 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashish0x90/633773 to your computer and use it in GitHub Desktop.
Save ashish0x90/633773 to your computer and use it in GitHub Desktop.
A quick python script which for Twitter Oauth system Given application key, application secret, asks user to authorize the application to enable Ouath access to his account by the application and prints those settings after process is over to be used lat
#!/usr/bin/env python
from webbrowser import open
import tweepy
"""
A small python script which given application key, and application secret, asks user to authorize application for Ouath access to his account and prints those settings to be used later.
Library Dependencies - twitter's python API interface - tweepy (http://joshthecoder.github.com/tweepy/)
For detailed info, refer to http://joshthecoder.github.com/tweepy/docs/auth_tutorial.html#oauth-authentication
"""
def get_oauth_consumer_keys():
application_key = raw_input(" Enter application_key: ")
application_secret = raw_input("Enter application_secret: ")
auth = tweepy.OAuthHandler(application_key,application_secret)
open(auth.get_authorization_url()) #User has to copy the the 6-digit pin number from here
verifier = raw_input("Enter the 6-digit pin number on the page: ")
access_token = auth.get_access_token(verifier)
user_key,user_secret = access_token.key,access_token.secret #save these values somewhere to be used later
if not validate_settings(application_key,application_secret,user_key,user_secret):
raise Exception("User couldn't be validated, try again")
print "Save following Settings to be used later:\n\n"
print "Application key: %s"%application_key
print "Application secret: %s"%application_secret
print '-'*50
print "User key : %s"%user_key
print "User secret : %s"%user_secret
def validate_settings(app_key,app_secret,user_key,user_secret):
auth = tweepy.OAuthHandler(app_key,app_secret)
auth.set_access_token(user_key,user_secret)
api = tweepy.API(auth)
return api.verify_credentials() #verify credentials
if __name__ == '__main__':
get_oauth_consumer_keys()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment