python - Difficulty with Twitter API Search -


i'm new python twitter api. have set auth twitter, , tried search works fine.

t = twitter.twitter(auth=auth)     tt = t.search.tweets(q="stackoverflow",rpp=50) 

this worked fine , can read output.

but if try:

for page in range(1,6):     tt = t.search.tweets(q="stackoverflow", rpp=100, page=page) 

this crashes error:

details: {"errors":[{"code":44,"message":"page parameter invalid"}]} 

i looked on twitter page , seems page parameter ok optional parameter: https://dev.twitter.com/docs/api/1/get/search.

alternatively, how more search results if rate limited 100 results per request. there work around it?

you should use max_id value iterate through results. make first request twitter api, read max_id result , send in next request.

from docs:

to use max_id correctly, application’s first request timeline endpoint should specify count. when processing , subsequent responses, keep track of lowest id received. id should passed value of max_id parameter next request, return tweets ids lower or equal value of max_id parameter. note since max_id parameter inclusive, tweet matching id returned again, shown in following image:

enter image description here

use twython:

from twython import twython  twitter = twython(app_key, access_token=access_token)  # initial request result = twitter.search(q='stackoverflow', count=100)  # max_id of results next_max_id = result['search_metadata']['next_results'].split('max_id=')[1].split('&')[0] # use max_id in next request  result = twitter.search(q='stackoverflow', count=100, max_id=next_max_id) 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -