Created
June 22, 2013 10:21
-
-
Save julen/5840310 to your computer and use it in GitHub Desktop.
An example Twitter search using the 1.1 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
#!/env/bin/python | |
import requests | |
from requests_oauthlib import OAuth1 | |
API_BASE = 'https://api.twitter.com/1.1/' | |
auth_url = API_BASE + 'account/verify_credentials.json' | |
tweets_url = API_BASE + 'search/tweets.json' | |
tweets_params = { | |
'q': '#hashtag', | |
'count': 100 | |
} | |
auth = OAuth1('YOUR_APP_KEY', 'YOUR_APP_SECRET', | |
'USER_OAUTH_TOKEN', 'USER_OAUTH_TOKEN_SECRET') | |
requests.get(auth_url, auth=auth) | |
tweets = requests.get(tweets_url, auth=auth, params=tweets_params) | |
for status in tweets.json()['statuses']: | |
print status['text'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment