PHPackages                             pdiazdumont/foursquare-api-php-wrapper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. pdiazdumont/foursquare-api-php-wrapper

ActiveLibrary[API Development](/categories/api)

pdiazdumont/foursquare-api-php-wrapper
======================================

Foursquare API PHP Wrapper

v1.0.0(10y ago)044MITPHP

Since Jan 27Pushed 10y ago1 watchersCompare

[ Source](https://github.com/pdiazdumont/foursquare-api-php-wrapper)[ Packagist](https://packagist.org/packages/pdiazdumont/foursquare-api-php-wrapper)[ Docs](https://github.com/pdiazdumont/foursquare-api-php-wrapper)[ RSS](/packages/pdiazdumont-foursquare-api-php-wrapper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Foursquare API PHP Wrapper
==========================

[](#foursquare-api-php-wrapper)

Introduction
------------

[](#introduction)

This project offers a more semantic way of accessing the Foursquare API using PHP. Instead of just wrapping the http requests it allows you to access the information using the following syntax:

```
$foursquare->venues('VENUE_ID')->get();
$foursquare->venues()->search($params);
$foursquare->users('USER_ID')->checkins();
```

**Features:**

- Full support of the Foursquare API including the Real time API.
- Compatible with the PSR-4 standard.
- Friendly commands to query the API.

Installation
------------

[](#installation)

This library can be installed using [Composer](http://getcomposer.org/) by running the following command:

```
composer require pdiazdumont/foursquare-api-php-wrapper

```

Usage
-----

[](#usage)

There are three use cases: requesting an access token from a user, querying the API and accessing the real time data. All these cases require the same code of initialization:

### Initialization

[](#initialization)

Require the autoloader in order to make all the wrapper classes available.

```
require 'vendor/autoload.php';
```

Include the API client class.

```
use PDiazDumont\Foursquare\Client;
```

Instantiate a new client. The required parameters are the application id and the application secret provided by Foursquare after registering your application.

```
$foursquare = new Client('APPLICATION_ID','APPLICATION_SECRET');
```

### Getting an access token from a user

[](#getting-an-access-token-from-a-user)

Certain API requests require permission from the users in order to access their information. The following code demonstrates how to retrieve and store the token that grants permission to your application.

```
require 'vendor/autoload.php';

use PDiazDumont\Foursquare\Client;

$foursquare = new Client('APPLICATION_ID','APPLICATION_SECRET');

/*
To perform the process of authentication only when needed, the client provides a helper
method called "isAuthenticated".
*/
if ($foursquare->isAuthenticated()) {
    return;
}

/*
The API client must know the redirect URL of the authentication process,
this URL must be equal to the one that is registered in your Foursquare application.
*/
$foursquare->setRedirectUrl('REDIRECT_URL');

/*
The link that the user needs to visit in order to give permission to your application is
generated using the method "getAuthenticationUrl".
*/
$url = $foursquare->getAuthenticationUrl();
header('Location: '. $url);

/*
After the user gives their permission, Foursquare will perform a redirect to the valid Redirect URL
defined in your application, adding a CODE parameter required to complete the process.
The "authenticate" method will exchange the CODE with a valid Access Token, setting it into the client.
*/
if (isset($_REQUEST['code'])) {
    $foursquare->authenticate();
}

/*
After the authentication process, the Access Token can be retrieved and saved for later use.
*/
$accessToken = $foursquare->getAccessToken();
// Save the Access token into a database or other alternative of persistent storage.
```

### Performing requests

[](#performing-requests)

The API client exposes a method for each of the resources available in the Foursquare API, this resources are: users, venues, venue groups, checkins, tips, lists, updates, photos, settings, specials, events and page updates. Each one of them has its own methods and arguments so the resulting structure of an api request is:

```
$foursquare->resource($resourceId)->method($methodParams)
```

Examples:

```
// Search for a venue
$venues = $foursquare->venues()->search([
    'll' => '44.3,37.2',
    'near' => 'Chicago, IL'
]);

// Get a list of the trending venues surrounding the user
$trending = $foursquare->venues()->trending([
    'll' => '44.3,37.2',
    'limit' => 10
]);

// Get a list of categories applied to venues
$categories = $foursquare->venues()->categories();

// Get information about a particular venue
$venue = $foursquare->venues('VENUE_ID')->get();

// Get information about the friends of a particular user
$friends = $foursquare->users('USER_ID')->friends();

// Get information about the checkins of a particular user
$friends = $foursquare->users('USER_ID')->checkins();

// Get information about the current user, note that the id is equal to "self"
$friends = $foursquare->users('self')->friends();
```

By reading the API documentation is easy to determine the methods that are available and the required arguments. The following code illustrates how to query the API, note that this time the access token is set directly.

```
require 'vendor/autoload.php';

use PDiazDumont\Foursquare\Client;

$foursquare = new Client('APPLICATION_ID','APPLICATION_SECRET');

/* To be able to query all the resources it is necessary to set a valid access token,
this token should be retrieved from a database or other type of storage, considering
that it was obtained previously.
*/
$foursquare->setAccessToken('ACCESS_TOKEN');

// Now everything's ready to perform requests
$data = $foursquare->users('self')->get();
echo "Welcome " . $data['user']['firstName'] . " " . $data['user']['lastName'];
```

### Real time API

[](#real-time-api)

This functionality can be activated in the Foursquare application dashboard and allows your application to receive a POST request every time one of your users do a checkin. The wrapper allows you to validate the request and extract the information received.

```
require '../vendor/autoload.php';

use PDiazDumont\Foursquare\Client;

$foursquare = new Client('APPLICATION_ID','APPLICATION_SECRET');

if ($foursquare->validateUserPush()) {
    $data = $foursquare->getUserPushData();
    // Do something with the push data.
}
```

Tests
-----

[](#tests)

To run the tests first you need to set an application id and an application secret in the file `tests/FoursquareAPICredentials.php` then run the `phpunit` command in the root folder of the project.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3755d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/61112aaa84ebcfee8f2e8cdfc8910c00403b37daf4f28924ddbc567b7a7ba931?d=identicon)[pdiazdumont](/maintainers/pdiazdumont)

---

Top Contributors

[![pdiazdumont](https://avatars.githubusercontent.com/u/1816197?v=4)](https://github.com/pdiazdumont "pdiazdumont (11 commits)")

---

Tags

apiwrapperfoursquare

### Embed Badge

![Health badge](/badges/pdiazdumont-foursquare-api-php-wrapper/health.svg)

```
[![Health](https://phpackages.com/badges/pdiazdumont-foursquare-api-php-wrapper/health.svg)](https://phpackages.com/packages/pdiazdumont-foursquare-api-php-wrapper)
```

###  Alternatives

[gabrielbull/ups-api

PHP UPS API

4642.4M10](/packages/gabrielbull-ups-api)[dariusiii/tmdb-laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

1821.1k](/packages/dariusiii-tmdb-laravel)[walle89/swedbank-json

Unofficial API client for the Swedbank's and Sparbanken's mobile apps in Sweden.

752.5k](/packages/walle89-swedbank-json)[lasserafn/laravel-economic

Economic REST wrapper for Laravel

1118.5k](/packages/lasserafn-laravel-economic)[sysmoh/nextcloud-api-wrapper

A simple wrapper around nextcloud user provisioning api

177.3k2](/packages/sysmoh-nextcloud-api-wrapper)[lasserafn/php-dinero

Dinero REST wrapper for PHP

115.2k](/packages/lasserafn-php-dinero)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
