Bill Shupp Software engineer, photographer, musician, space geek


Importing foursquare checkins into SimpleGeo with PHP

SimpleGeo recently blogged about exploring foursquare check-ins on a map with their service.  I'd been looking for an excuse to play with their API, so I decided to port the example in their blog (which is in python) to PHP.  Read their blog first, as it covers the process in more detail.  Just substitute their examples with the ones below.

A broader PHP tutorial for using their API is available in their documentation, but for the impatient, here's a quick install of their PHP client.  It assumes you already have a working PEAR installation:

pear install HTTP_Request2-alpha
pear install HTTP_OAuth-alpha
pear install Net_URL2
git clone git://
cd Services_SimpleGeo
pear install package.xml

And here's the actual example in PHP, which you can run from CLI:

When running it, you should see progress:

$ php sg_4sq_example.php

Sending batch 1
Sending batch 2

Once it's complete, go to your SimpleGeo dashboard, click on the the explorer tab for the layer you're using, and you'll see something like this, which is a history of my check-ins in San Francisco:

My local foursquare checkins on SimpleGeo

I only ran into a couple of issues with getting this working in PHP.  First, getting the right syntax for extracting the coordinates from the RSS feed took some time to get right.  I first tried with PEAR's XML_Feed_Parser, but ended up just using SimpleXML directly.  Second, the blog example uses raw guid values, which break the API call when they contain a '/'.  Unfortunately, the error returned by the API was not that useful: 'dict' object has no attribute 'startswith'.  Once I noticed the slash in the value, wrapping the guid in base64_encode() fixed the problem.

Perhaps you'll find this useful, it was fun to finally use the SimpleGeo API!

Comments (1) Trackbacks (1)
  1. This is awesome Bill, thanks for posting. I updated the SimpleGeo blog with a link to this.

Leave a comment