编程语言
首页 > 编程语言> > php-使用API​​获取Gowalla签入历史

php-使用API​​获取Gowalla签入历史

作者:互联网

我一直在使用Gowalla API,并且想知道是否有人找到一种方法来获取所有最近签入的列表(只是您自己的,不包括朋友).该文档非常糟糕.

解决方法:

您可以使用他们的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
)

标签:curl,api,geolocation,php,social-networking
来源: https://codeday.me/bug/20191106/1999466.html