-2

I know that Twitter search API has it's own limitations and returns much less search results rather than the actual results but I was searching through a popular hashtag and it only returns 60 result which is not acceptable at all!

here is my code in which I've used twython module.

results = {}
last_id = None
count = 0
while(len(results.keys()) != min_count):
    if(last_id):
        tmp_results = self.api.search(q="#mentionsomeoneimportantforyou", count=100, max_id=last_id)
    else:
        tmp_results = self.api.search(q=#mentionsomeoneimportantforyou, count=100)
    count += len(tmp_results['statuses'])
    print("new len:  ", count)
    last_id = get_max_id(tmp_results)


def get_max_id(results):
    next_results_url_params = results['search_metadata']['next_results']
    next_max_id = next_results_url_params.split('max_id=')[1].split('&')[0]
    return next_max_id

Is there anything run with this code? It not, isn't 60 of many a joke?

Pooya
  • 992
  • 2
  • 10
  • 31

2 Answers2

0

The twython docs suggest not doing it that way, using the cursor approach instead:

twitter = Twython(APP_KEY, APP_SECRET,
                  OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

results = twitter.cursor(twitter.search, q='python')
count = 0
for result in results:
    print result['id_str']
    count += 1
print count

prints:

... many here ...
561918886380322816
561918859050229761
561919180480737282
561919151162130434
561919142450581504
561919113812246529
561919107134922753
561919103867559938
561919077481218049
561918994454556672
561918971755372546
561918962381127680
561918948288258048
561918911751655425
561918904126042112
561918886380322816
561918859050229761
645
bgporter
  • 35,114
  • 8
  • 59
  • 65
0

I think I found the reason. According to this link Twitter doesn't return tweets older than a week through search api.

Pooya
  • 992
  • 2
  • 10
  • 31