skip to Main Content

My request only returns twenty or so hits. Notice I set the radius to be 5000km which is ridiculous, that’s because I used 50 first but got too few hits, so I increased it. But even at 5000km, I’m still getting the same few results. I’m using Python 3.5.

Here is the code:

import tweepy

consumer_key = 'xxxxx'
consumer_secret = 'xxxxxxxxx'
access_token = 'xxxxxxx'
access_token_secret = 'xxxxxxxxxxxxxxx'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)
results = api.search(q="Global Warming",geocode="40.7142700,-74.0059,5000km",count=100)
for result in results:
    print (result.text.encode('utf-8'))

2

Answers


  1. Twitter limits how far back in the past you can search to about one week. You have reached that limit. You can see this for yourself if you inspect the created_at field of the last tweet returned.

    Login or Signup to reply.
  2. You are probably missing on tweets which:

    • Lack location
    • Located outside of 1,000 distinct “sub-regions” from given location

    When searching on tweets with the geocode field, the API will first search for tweets with geolocation specified, otherwise it will use the location from the user profile.

    From the Search API on Geolocalization:

    Geolocalization: The search operator “near” isn’t available in API,
    but there is a more precise way to restrict your query by a given
    location using the geocode parameter specified with the template
    “latitude,longitude,radius”, for example, “37.781157,-122.398720,1mi”.
    When conducting geo searches, the search API will first attempt to
    find tweets which have lat/long within the queried geocode, and in
    case of not having success, it will attempt to find tweets created by
    users whose profile location can be reverse geocoded into a lat/long
    within the queried geocode, meaning that is possible to receive tweets
    which do not include lat/long information.

    From the search/tweets doc:

    A maximum of 1,000 distinct “sub-regions” will be considered when using the radius modifier.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search