How can I add geocode in query?


#1

geocode=‘42.331429,-83.045753,30km’
api=TwitterAPI(key,secreyt_key,token,secret_token)
r = api.request(‘tweets/search/%s/:%s’ % (PRODUCT, LABEL),
{‘geocode’:geocode,‘fromDate’:201801010000,‘toDate’:201801020000,‘maxResults’:500})

This is my code, but it keeps occuring error. TwitterAPI.TwitterError.TwitterRequestError: Twitter request failed (422)
I don’t think it’s impossible to add geocode in this query, but I don’t know how to add it. Is my geocode right?
Or is it impossible to add geocode in ‘request’ method while I’m using geduldig’s(https://github.com/geduldig) TwitterAPI?

p.s. I’m using premium api.


#2

Take a look at the premium search operators documentation - there’s no geocode parameter, but you can use place, bounding_box or point_radius inside your query.


#3

Then, how can I add bounding_box or point_radius in my query? I mean, I’m asking the exact form of point_radius(or bounding_box) in python.
I tried ‘point_radius’:‘42.331429,-83.045753,1km’ and ‘bounding_box’:‘42.3,-83.3,42.5,-83’ but nothing worked.
I think that knowing the exact form of query related to location matters because when I use query not including that it works very well (i.e.
r = api.request(‘tweets/search/%s/:%s’ % (PRODUCT, LABEL),{‘fromDate’:201901220000,‘toDate’:201901290000})
I searched github and google to find code using premium api and point_radius simultaneously, but I have found nothing…


#4

I just tried this:

r = api.request('tweets/search/%s/:%s' % (PRODUCT, LABEL),
                {'query': 'Apple point_radius:[2.355128 48.861118 16km]'})

This worked for my 30-day premium request, finding Tweets including the word Apple up to 16km from the centre of Paris, France.

It also works with the counts endpoint (if you have a paid plan):

r = api.request('tweets/search/%s/:%s/counts' % (PRODUCT, LABEL),
                {'query': 'Apple point_radius:[2.355128 48.861118 16km]', 'bucket': 'day'})

This returns a timeseries containing the number of times that search pattern occurred every day over a month.

Bear in mind that only a very small percentage of Tweets overall carry geo data. This is a user preference.


#5

Thank you. THANK YOU VERY MUCH IT WORKS!!
Now I can collect data for my paper. I want to hug you. THANK YOU!


closed #6