Nabbing your Gowalla activity history with their API and PHP

The background to this is that my wife and I love traveling to Disney World. On a trip last year, I used Gowalla to record most of things we did while we were there. My wife enjoys writing up our trips, in combination with the photos of those trips, and this record from Gowalla was a handy resource in creating those trip reports.

Gowalla says they will get the activity history up on their website soon: that may already be the case by the time you read this. They’re busy folks, though, so I didn’t want to wait.

I tried looking around for a functional Drupal module to do the job, but I did not have much luck.

So instead I dug around and found a solution using their API.

Google brought me to a question-and-answer site with a suggested solution..

I tweaked this a bit to suit my needs:

$username = 'INSERT YOUR USERNAME HERE';
$api_key = 'INSERT YOUR API KEY HERE';
$checkin_num = 500;
$url = "http://api.gowalla.com/users/{$username}/stamps?limit={$checkin_num}";

// setup curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array (
    "Accept: application/json",
    "X-Gowalla-API-Key: {$api_key}",
));
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body, true);
foreach($json['stamps'] as $stamp) {
print '<h2>';
print $stamp['spot']['name'];
print '</h2>';
print '<p><em>';
print $stamp['last_checkin_at'];
print '</em></p>';
}

It’s pretty easy to get an API key for Gowalla. The only tricky part was the OAUTH 2 callback URL. I just made up a URL on my site to get that to work, and it didn’t cause any problems.

You can change $checkin_num as you please to whatever you like to determine how far back you want to go.

If you want to include some additional information, just add this into the foreach loop:

    print "<pre>";
    print_r($stamp);
    print "</pre>";

That will show you the full range of options you can retrieve. Just plug those options into the code, and away you go!

The date formatting is pretty awkward. It probably wouldn’t take much work to mung that data into a more readable format.

Like I said, you may not need this for much longer, but if you want to make sure you retrieve your Gowalla activity history for archiving purposes, this might be useful to you.

Archives