简体   繁体   English

使用API​​获取Gowalla登记历史记录

[英]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 your own, not including friends). 我一直在玩Gowalla API,并且想知道是否有人找到了获取所有最近签到的列表的方法(只是你自己的,不包括朋友)。 The documentation is quite awful. 文档非常糟糕。

You can use their API Explorer to see what's available in terms of the API. 您可以使用他们的API资源管理器查看API方面的可用内容。 It's pretty neat and serves as nice documentation, just look at the REST style URLs. 它非常整洁,可作为很好的文档,只需查看REST样式的URL即可。

Here's basic code to get the last 5 checkins. 这是获取最后5张签到的基本代码。 You will need an API Key. 您将需要一个API密钥。

$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: 这是checkin'tamp 'stamp'对象的样子:

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. 使用http://api.gowalla.com/users/USERNAME/events获取用户的所有签到。 Use the page parameter to get results beyond the first page. 使用page参数可以获得超出第一页的结果。 Don't forget to pass the Accept header with the application/json value, or Gowalla will simply return 500 error. 不要忘记使用application/json值传递Accept标头,否则Gowalla将只返回500错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM