views:

81

answers:

1

I have been playing around with the Gowalla API, and was wondering if anyone has found a way to get a list of all recent checkins (just your own, not including friends). The documentation is quite awful.

+2  A: 

You can use their API Explorer to see what's available in terms of the API. It's pretty neat and serves as nice documentation, just look at the REST style URLs.

Here's basic code to get the last 5 checkins. You will need an API Key.

$username = 'sco';
$api_key = 'f6cd524ac9c4413abfb41d7123757d9';
$checkin_num = 5;
$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 $stamp['spot']['name'] . '<br/>';
    print "<pre>";
    print_r($stamp);
    print "</pre>";
}

Here's what a checkin 'stamp' object looks like:

Array
(
    [spot] => Array
        (
            [image_url] => http://static.gowalla.com/categories/24-standard.png
            [url] => /spots/19890
            [lat] => 38.9989524833
            [address] => Array
                (
                    [locality] => Kansas City
                    [region] => MO
                )

            [lng] => -94.5939345333
            [name] => The GAF Pub & Grille
        )

    [first_checkin_at] => 2010-06-12T19:16:57+00:00
    [checkins_count] => 1
    [last_checkin_at] => 2010-06-12T19:16:57+00:00
)
artlung
awesome, thank you very much.
Bruack
Glad to help. Welcome to StackOverflow!
artlung