hownowstephen/php-foursquare 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hownowstephen/php-foursquare

Composer 安装命令:

composer require hownowstephen/php-foursquare

包简介

A simple PHP library for accessing the foursquare API (see: https://developer.foursquare.com)

README 文档

README

I couldn't find a php library for the Foursquare API that encapsulated all the functionality of the API while still remaining easy to plug in to an application quickly. This library seeks to fill that need.

Installation

The best way to install Foursquare library is to use Composer:

composer require hownowstephen/php-foursquare:'1.2.*'

If you are not using an autoloader, you need to require_once the autoload file:

require_once 'vendor/autoload.php';

Another way to install is to download the latest version directly from this repository.

Usage

This library wrappers for php applications to make requests to both public and authenticated-only resources on Foursquare. As well it provides functions that encapsulate the main methods needed to retrieve an auth_token for a user from Foursquare. Instead of having explicit functions for calling API endpoints, you can call individual endpoints directly by their path (eg. venues/40a55d80f964a52020f31ee3/tips)

Querying the API

$foursquare = new FoursquareApi("<your client key>", "<your client secret>");

// Searching for venues nearby Montreal, Quebec
$endpoint = "venues/search";
	
// Prepare parameters
$params = array("near"=>"Montreal, Quebec");

// Perform a request to a public resource
$response = $foursquare->GetPublic($endpoint,$params);

// Returns a list of Venues
// $POST defaults to false
$venues = $foursquare->GetPublic($endpoint [,$params], $POST=false);
		
// Note: You don't need to add client_id, client_secret, or version to $params

// Setting the access token to enable private requests
// See examples/tokenrequest.php for how to retrieve this
$auth_token = "<your auth token>";
$foursquare->SetAccessToken($auth_token);

// Request a private endpoint (Requires Acting User)
$endpoint_private = "users/self";

// Returns a single user object
$me = $foursquare->GetPrivate($endpoint_private);
// Note: You don't need to add oauth_token to $params

Authenticating the user (see examples/tokenrequest.php)

$foursquare = new FoursquareApi("<your client key>", "<your client secret>");

// Some real url that accepts a foursquare code (see examples/tokenrequest.php)
// This URL should match exactly the URL given in your foursquare developer account settings
$redirect_url = "http://localhost/foursquare_code_handler";

// Generates an authentication link for you to display to your users
// (https://foursquare.com/oauth2/authenticate?...)
$auth_link = $foursquare->AuthenticationLink($redirect_url);
		
// Converts an authentication code (sent from foursquare to your $redirect_url) into an access token
// Use this on your $redirect_url page (see examples/tokenrequest.php for more)
$code = $_GET['code'];	

$token = $foursquare->GetToken($code, $redirect_url);

// again, redirect_url must match the one you set in your account exactly
// and here is where you would store the token for future usage

Adding features & testing

If you want to commit features, please also update the tests/FoursquareApiTest.php file with a proper unit test - this will ensure changes can be accepted more quickly.

Running tests requires phpunit, and can be run as the following:

export FOURSQUARE_CLIENT_ID=<your client id>
export FOURSQUARE_CLIENT_SECRET=<your client secret>
export FOURSQUARE_TOKEN=<your access token>
phpunit --bootstrap src/FoursquareApi.php tests/FoursquareApiTest.php

PROTIP: The easiest way to get an access token to test with is to look yourself up in the api explorer and pull it directly from the grayed-out url information (OAuth token automatically added. https://api.foursquare.com/v2/users/self?oauth_token=...) underneath the input box.

What else do I need?

This library does not deal with the management of your tokens - only the interaction between your code and the Foursquare API. If you are using it in an application that needs to use user data via an auth_token, you will need to store the token across sessions separately from the library.

hownowstephen/php-foursquare 适用场景与选型建议

hownowstephen/php-foursquare 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 176.34k 次下载、GitHub Stars 达 168, 最近一次更新时间为 2014 年 07 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 hownowstephen/php-foursquare 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hownowstephen/php-foursquare 我们能提供哪些服务?
定制开发 / 二次开发

基于 hownowstephen/php-foursquare 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 176.34k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 168
  • 点击次数: 22
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 168
  • Watchers: 20
  • Forks: 66
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-07-03