开发者

Getting Gowalla Check-in history using API

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 y开发者_StackOverflowour own, not including friends). The documentation is quite awful.


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
)


Use http://api.gowalla.com/users/USERNAME/events to get all checkins for a user. Use the page parameter to get results beyond the first page. Don't forget to pass the Accept header with the application/json value, or Gowalla will simply return 500 error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜