【发布时间】:2025-11-24 05:30:01
【问题描述】:
我一直在使用 Gowalla API,想知道是否有人找到了一种方法来获取所有最近签到的列表(只是你自己的,不包括朋友)。文档很糟糕。
【问题讨论】:
标签: php api curl geolocation social-networking
我一直在使用 Gowalla API,想知道是否有人找到了一种方法来获取所有最近签到的列表(只是你自己的,不包括朋友)。文档很糟糕。
【问题讨论】:
标签: php api curl geolocation social-networking
您可以使用他们的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
)
【讨论】:
使用http://api.gowalla.com/users/USERNAME/events 获取用户的所有签到。使用page 参数可以获得第一页以外的结果。不要忘记使用 application/json 值传递 Accept 标头,否则 Gowalla 将简单地返回 500 错误。
【讨论】: