Skip to content

Instantly share code, notes, and snippets.

@julen
Created June 22, 2013 10:21
Show Gist options
  • Save julen/5840310 to your computer and use it in GitHub Desktop.
Save julen/5840310 to your computer and use it in GitHub Desktop.
An example Twitter search using the 1.1 API.
#!/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