Created
September 14, 2013 07:55
-
-
Save naiquevin/6559771 to your computer and use it in GitHub Desktop.
Twython wrapper for app authenticated requests to twitter api
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
from twython import Twython | |
## Defining access_token as a function so that the token may be cached | |
## using a decorator as follows, | |
## | |
## get_access_token = cache_textfile('.twython-token')(access_token) | |
## | |
def access_token(auth_client): | |
return auth_client.obtain_access_token() | |
def app_auth_client(app_key, app_secret): | |
tw_auth = Twython(app_key, app_secret, oauth_version=2) | |
return Twython(app_key, access_token=access_token(tw_auth)) | |
if __name__ == '__main__': | |
# example | |
twitter = app_auth_client(APP_KEY, APP_SECRET) | |
results = twitter.search(q='pyconindia2013', count='100') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment