Authorizing a twitter-bot

So last night I ran into a small issue, how to authorize a twitter bot to use an application without stubbing together a website and logging in with the bot account?  The answer, this little script using twython:

import twython
app_key = raw_input("Your app key: ")
app_secret = raw_input("Your app secret: ")
twitter = twython.Twython(app_key, app_secret)
auth = twitter.get_authentication_tokens()
print "Log into Twitter as the user you want to authorize and visit this URL:"
print "\t" + auth['auth_url']
pin = raw_input("Enter your PIN: ")
twitter = twython.Twython(app_key, app_secret, auth['oauth_token'], auth['oauth_token_secret'])
tokens = twitter.get_authorized_tokens(pin)
print "Your token: " + tokens['oauth_token']
print "Your token secret: " + tokens['oauth_token_secret']

Source: https://gist.github.com/moonmilk/035917e668872013c1bd#gistcomment-1398946

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply