Trying to get tweets from geolocation and date range only in Full-Archive
Using python requests package for get access.
A few problems :
- search params requires text value in ‘query’ field …
- cannot find method to include geolocation for tweet in get() command … tried using filter_rule with point_radius argument, but API returns status code = 422 in all cases
So :
- is there a way to get (all) tweets from a geo-location within a date range - regardless of any tweet content ?
Here is the python code that I have been trying to use :
import base64
import json
import requests
key_secret = ‘{}:{}’.format(client_key, client_secret).encode(‘ascii’)
b64_encoded_key = base64.b64encode(key_secret)
b64_encoded_key = b64_encoded_key.decode(‘ascii’)
base_url = ‘https://api.twitter.com/’
auth_url = ‘{}oauth2/token’.format(base_url)
auth_headers = {
‘Authorization’: ‘Basic {}’.format(b64_encoded_key),
‘Content-Type’: ‘application/x-www-form-urlencoded;charset=UTF-8’
}
auth_data = {
‘grant_type’: ‘client_credentials’
}
auth_resp = requests.post(auth_url, headers=auth_headers, data=auth_data)
print("auth_resp.status_code = : ", auth_resp.status_code)
auth_resp.json().keys()
access_token = auth_resp.json()[‘access_token’]
search_headers = {
‘Authorization’: ‘Bearer {}’.format(access_token)
}
search_params = {
‘query’: 'CAN I MAKE THIS BLANK ?? ',
‘filter_rule’ : ‘point_radius : [-84.512016 39.103119 50km]’, # returns status code = 422 !!
‘fromDate’: ‘201808010000’,
‘toDate’: ‘201808240259’,
‘maxResults’ : ‘100’
}
search_url = ‘{}1.1/tweets/search/fullarchive/fullSearchSandbox.json’.format(base_url)
print(‘search_url = ‘, search_url)
print(’\n’)
print('search_params = ', search_params)
search_resp = requests.get(search_url, headers = search_headers, params = search_params)
print("search_resp.status_code = : ", search_resp.status_code)
tweet_data = search_resp.json()