Created
February 12, 2013 18:45
-
-
Save hezhao/4772180 to your computer and use it in GitHub Desktop.
Twitter PIN-based authorization using tweepy
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
### See PIN-based authorization for details at | |
### https://dev.twitter.com/docs/auth/pin-based-authorization | |
import tweepy | |
consumer_key=<your_app_consumer_key> | |
consumer_secret=<your_app_consumer_secret> | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
# get access token from the user and redirect to auth URL | |
auth_url = auth.get_authorization_url() | |
print 'Authorization URL: ' + auth_url | |
# ask user to verify the PIN generated in broswer | |
verifier = raw_input('PIN: ').strip() | |
auth.get_access_token(verifier) | |
print 'ACCESS_KEY = "%s"' % auth.access_token.key | |
print 'ACCESS_SECRET = "%s"' % auth.access_token.secret | |
# authenticate and retrieve user name | |
auth.set_access_token(auth.access_token.key, auth.access_token.secret) | |
api = tweepy.API(auth) | |
username = api.me().name | |
print 'Ready to post to ' + username |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update Python 3.9.8, Tweepy 4.40: