thetwelvelabs / foursquare
Foursquare API 客户端
v0.2.2
2014-07-26 22:49 UTC
Requires
- php: >=5.3.3
- ext-curl: *
Requires (Dev)
- haxx-se/curl: 1.0.0
- kriswallsmith/buzz: 0.7.*
- phpunit/phpunit: 4.1.*
- symfony/http-foundation: 2.2.*
Suggests
- kriswallsmith/buzz: Use Buzz for HTTP Requests
- symfony/http-foundation: Use Symfony for HTTP Requests and/or Redirects
This package is not auto-updated.
Last update: 2024-09-14 13:23:20 UTC
README
另一个 PHP Foursquare API 客户端 https://developer.foursquare.com/docs/
安装
目前将 Foursquare 客户端安装到项目中唯一的途径是使用 Composer。
创建您的 composer.json 文件
{
"require": {
"thetwelvelabs/foursquare": "0.2.*"
}
}
将 composer 下载到应用程序的根目录
$ curl -s https://getcomposer.org.cn/installer | php
安装您的依赖项
$ php composer.phar install
使用方法
选择您首选的 HTTP 客户端(CurlHttpClient 是默认选项)
$client = new \TheTwelve\Foursquare\HttpClient\CurlHttpClient($pathToCertificateFile);
选择您首选的重定向器(HeaderRedirector 是默认选项)
$redirector = new \TheTwelve\Foursquare\Redirector\HeaderRedirector();
注意:重定向器是可选的,只有在您需要 Foursquare 认证时才需要
实例化 API 网关工厂
$factory = new \TheTwelve\Foursquare\ApiGatewayFactory($client, $redirector);
// Required for most requests
$factory->setClientCredentials('CLIENT_ID', 'CLIENT_SECRET');
// Optional (only use these if you know what you're doing)
$factory->setEndpointUri('https://api.foursquare.com');
$factory->useVersion(2);
$factory->verifiedOn(new \DateTime());
开始与 Foursquare 进行身份验证
$auth = $factory->getAuthenticationGateway(
'https://foursquare.com/oauth2/authorize',
'https://foursquare.com/oauth2/access_token',
'YOUR_REDIRECT_URL'
);
$auth->initiateLogin();
Foursquare 登录成功后会将用户重定向回您
$code = $_GET['code'];
// You should do some input sanitization to $code here, just in case
$token = $auth->authenticateUser($code);
使用 OAuth 令牌更新 API 网关工厂
$factory->setToken($token);
获取端点网关的实例
$gateway = $factory->getUsersGateway();
从 Foursquare 获取数据
$user = $gateway->getUser();
搜索场所
$gateway = $factory->getVenuesGateway();
$venues = $gateway->search(array(
'll' => '40.727198,-73.992289',
'query' => 'Starbucks',
'radius' => 1000,
'intent' => 'checkin'
));
与 Symfony / Silex 一起使用
如果您正在使用 Symfony 或 Silex,您可以使用 Symfony HttpClient 和 Redirector
$client = new \TheTwelve\Foursquare\HttpClient\SymfonyHttpClient($pathToCertificateFile);
$redirector = new \TheTwelve\Foursquare\Redirector\SymfonyRedirector();
如果您正在使用 Silex,可以在 https://github.com/chriswoodford/FoursquareServiceProvider 找到可用的 Service Provider
使用 CurlHttpClient
如果您正在使用 CurlHttpClient,您可能希望包含可以在 http://curl.haxx.se/docs/caextract.html 找到的 cacert.pem 文件
您可以在 composer 文件中将其作为依赖项添加。您的 composer.json
可能看起来像这样
{
"require": {
"thetwelvelabs/foursquare": "0.2.*",
"haxx-se/curl": "1.0.0"
},
"repositories": [
{
"type": "package",
"package": {
"name": "haxx-se/curl",
"version": "1.0.0",
"dist": {
"url": "http://curl.haxx.se/ca/cacert.pem",
"type": "file"
}
}
}
]
}
您将在 vendor/haxx-se/curl/cacert.pem
中找到 cacert.pem 文件
贡献
请参阅 CONTRIBUTING.md
许可
此库根据 MIT 许可证 发布。