Last active
August 29, 2015 14:06
-
-
Save edsu/6d184f0e807a8c9bb75e to your computer and use it in GitHub Desktop.
Add your Twitter credentials to your environment, run this and notice how the second request yields only one tweet? Try running again with a sleep between them (uncomment line 27) and notice how the second request finds results this time? This seems to be a bug, or a new "feature" intended to prevent using the API to walk backwards in search res…
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
#!/usr/bin/env python | |
# you'll need to install python's oauth2 for this to work | |
import os | |
import json | |
import time | |
import oauth2 | |
ck = os.environ.get('CONSUMER_KEY') | |
cks = os.environ.get('CONSUMER_SECRET') | |
at = os.environ.get('ACCESS_TOKEN') | |
ats = os.environ.get("ACCESS_TOKEN_SECRET") | |
consumer = oauth2.Consumer(key=ck, secret=cks) | |
token = oauth2.Token(at, ats) | |
client = oauth2.Client(consumer, token, timeout=60) | |
q = 'dconstruct' | |
print "request #1" | |
resp, content = client.request('https://api.twitter.com/1.1/search/tweets.json?count=100&q=%s' % q) | |
for s in json.loads(content)['statuses']: | |
print s['id_str'] | |
last_id = int(s['id_str']) | |
# time.sleep(20) | |
print "request #2" | |
resp, content = client.request('https://api.twitter.com/1.1/search/tweets.json?count=100&q=%s&max_id=%i' % (q, last_id)) | |
for s in json.loads(content)['statuses']: | |
print s['id_str'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment