You are here

How to Use Twitter API and PHP to Locate Eyewitnesses

Geotagging is the process of embedding latitude, longitude, and even altitude coordinates in some type of media, such as a photo, video or promotional offer. Many people don’t realise it, but modern mobile phones are constantly recording our movements and making that information available to network providers, and sometimes even third-parties willing to pay for the data.

As the second installment in a two-part Tuts+ series on harnessing location data from social media, Jeff Reifman discussed using the Twitter APITrack this API to find eyewitnesses to a public event. In this case it was President Obama’s speech at the Edmund Pettus Bridge in Selma back in March. The author begins by registering a developer application with Twitter using the relevant access tokens for the account.

Reifman then sets up an Active Record migration to store the tweets received from the API, before using Google Maps to get the GPS coordinates of the bridge. The Twitter API’s limitations to search only by date within the last 7 days means that the search does require some refinements. This application makes requests to Twitter at the given coordinates on the specified date, with Reifman recording only those tweets that occurred during his desired time range.

Twitter returns up to 100 tweets per API call, so this application begins at the end of the specified day, working backwards in time to request additional records that are earlier than the previous batch. This process is looped until fewer than 100 records are returned or when tweets are earlier than the specified date range.

With all of the results returned, followers can browse the recorded tweets to perform the intended task, whatever that may be. This “Eyewitness App” is built in the Yii framework for PHP. All of the code is provided, as well as links to the complete code repository on GitHub.

Be sure to read the next Geography article: As the Google Earth API Shutdown Nears, What Are Your Options?

Original Article

Using Social Media to Locate Eyewitnesses: The Twitter API