jcroll / foursquare-api-bundle
用于 jcroll/foursquare-api-client 的 Symfony 扩展包
Requires
Requires (Dev)
- phpunit/phpunit: ~4.8|^5
This package is not auto-updated.
Last update: 2024-09-28 14:01:47 UTC
README
此扩展包将 JcrollFoursquareApiClient 集成到 Symfony 框架中。
为什么?
此扩展包将允许您轻松配置 JcrollFoursquareApiClient,并额外允许您轻松集成 HWIOAuthBundle(如果您正在使用它)以对 foursquare API 进行签名请求(有关示例,请参阅 JcrollFoursquareApiBundleSandbox)。
安装
在您的 composer.json 中添加 JcrollFoursquareApiBundle
{ "require": { "jcroll/foursquare-api-bundle": "~1" } }
下载扩展包
$ php composer.phar update jcroll/foursquare-api-bundle
将 JcrollFoursquareApiBundle 添加到您的 AppKernel.php
// app/AppKernel.php public function registerBundles() { $bundles = array( ... new Jcroll\FoursquareApiBundle\JcrollFoursquareApiBundle(), ... ); ... }
基本配置
-
如果您不使用 HWIOAuthBundle,请添加您的应用程序 ID 和密钥参数(其他参数是可选的)
# app/config/config.yml jcroll_foursquare_api: client_id: <your_foursquare_client_id> client_secret: <your_foursquare_client_secret> version: 20140806 # optional mode: foursquare # optional
-
如果您使用 HWIOAuthBundle,请配置一个
foursquare资源所有者和客户端凭据将自动配置(除非您希望为version或mode指定自定义值)。# app/config/config.yml hwi_oauth: resource_owners: any_name: type: foursquare client_id: <your_foursquare_client_id> # will automatically inject in the client client_secret: <your_foursquare_client_secret> # will automatically inject in the client
使用方法
$client = $this->container->get('jcroll_foursquare_client'); $client->setToken($oauthToken); // optional for user specific requests $client->setMode('swarm'); // switch from mode 'foursquare' to 'swarm' $command = $client->getCommand('venues/search', [ 'near' => 'Chicago, IL', 'query' => 'sushi' ]); $results = (array) $client->execute($command); // returns an array of results
您可以在扩展包的 client.json 中找到客户端可用命令的列表,但基本上它们应该与文档中列出的 api 端点 相同。
HWIOAuthBundle 集成
如果您使用 HWIOAuthBundle,此扩展包将自动在该扩展包的配置中查找类型为 foursquare 的 resource_owner,并将 client_id 和 client_secret 注入到 jcroll_foursquare_client 服务中(除非您想为 version 或 mode 定义自定义值,否则无需配置此扩展包)。
此外,将配置一个监听器,如果经过身份验证的用户拥有属于 foursquare 的 OAuth 令牌,则该令牌将自动注入到 jcroll_foursquare_client 服务中进行签名请求(无需调用 setToken)。