Getting all tweets around the world using Twitter REST API


#1

I am trying to get all the tweets using the GET search/tweets of the Twitter REST API and map them onto Google Maps.

I am running to different queries:

To get all tweets in a radius based on the user location.

$lat = $_REQUEST['lat'];
$lon = $_REQUEST['lon'];
$rad = $_REQUEST['rad'];
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=&count=100&result_type=recent&lang=en&geocode='.$lat.','.$lon.','.$rad.'mi';

To get all tweets irrespective of the user location. So what I want is all tweets around the world.

$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=&count=100&result_type=recent&lang=en';

The 1st query returns a JSON with all the tweets but I get an error in the 2nd query saying “Query parameters are missing”.

Note: In the 1st query the “q” parameter is also set to null likewise in the 2nd query.

I wanted to know the reason for the same.


#2

The Search API is documented on the developer website. You cannot do a query of this kind which omits both the search term and the geolocation, as the error tells you. You can search for tweets by location, or you can search of tweets matching a pattern without specifying a location. At the moment you’re not actually searching for anything.

For “1% of all tweets happening now” you could use the Streaming API sample endpoint instead of trying to use search…


#3

Okay. I can try using the Streaming API. Thank you for the information Andy.