使用 API 获取 Gowalla 签到历史记录

发布于 2024-09-05 01:31:25 字数 74 浏览 9 评论 0原文

我一直在研究 Gowalla 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). The documentation is quite awful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初与友歌 2024-09-12 01:31:25

您可以使用他们的 API Explorer 查看 API 方面的可用内容。它非常简洁,并且可以作为很好的文档,只需查看 REST 样式 URL 即可。

以下是获取最近 5 次签到的基本代码。您将需要一个 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>";
}

这是签入 '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
)

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
)
南汐寒笙箫 2024-09-12 01:31:25

使用 http://api.gowalla.com/users/USERNAME/events 获取所有用户签到。使用 page 参数获取第一页以外的结果。不要忘记传递带有 application/json 值的 Accept 标头,否则 Gowalla 将简单地返回 500 错误。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文