Mar 112015

A website with information of any kind about a certain geographical location might find interesting to include a list of places, points of interest, businesses and services available in that area.

Yelp is one of the possible choices, together with Google Places, Facebook, etc. for a service provider that implements an API that can be used to retrieve that kind of information. This post explains how to query the Yelp API from a PHP script to obtain a list of nearby places.

Characteristics of the Yelp service

The Places API can be used to search for businesses, services and landmarks around a given point expressed as a (longitude,latitude) coordinate pair, or contained in a bounding box. The results can also be filtered based on categories.

The service is free of charge, with a limit of 10.000 requests/day.

Besides, there is an affiliate program through Commision Junction. Websites that publish business deals from Yelp can obtain an extra income in this way.

Obtaining access keys

Requests to the API must be authenticated with OAuth. Thus, the first step to use the API is obtaining a pair of keys from the “Manage API Access” page in the Yelp Developers website.

First, go to and register as a Yelp user.

Then, go to The signup as developer is automatically done, and a confirmation email is sent to the email address entered. To proceed, the confirmation link in the message received must be clicked.

Next, go to “Manage API Access“, and fill the form displayed with the applicable information:


After the form has been submitted, the access keys are displayed. Copy and save them in a safe place:


Download and installation of the PHP library

To send signed requests to the API, a library implementing the OAuth protocol must be used. The easiest way to get the library is by downloading the package from the github page for the Yelp API.

The package is uncompressed into a directory tree with samples for a good number of programming languages, including Java, C#, Perl and PHP.

Specifically, the PHP OAuth library can be found in yelp-api-master/v2/php/lib/OAuth.php. There is also a sample PHP script in yelp-api-master/v2/php/sample.php

Issuing a simple query

The sample script “sample.php” can be analyzed to understand how to access the Yelp API from a PHP script.

The sample script queries for places to have dinner in San Francisco, CA. This is done with an authenticated access to the url:

(Where “San+Francisco%2c+CA” is the result of encoding “San Francisco, CA” as a valid URL).

First, the script loads the OAuth library, and defines several variables:

Then, the request is created, and signed with the OAuth credentials:

Finally, te signed URL is used to access the API. The response in JSON format is converted to a PHP structure and printed to standard output:

And this is the result:

Coordinate based searches

In the previous sample, the location to be searched was specified as free text in the value of the “location” parameter: “location=San+Francisco%2C+CA”.

The location can be more precisely specified with the “ll” parameter, whose value is a (latitude,longitude) coordinate pair. “ll” is commonly used in conjunction with the “radius_filter” parameter, to specify the maximum distance in meters that returned businesses should be from the the point.

Another possibility is to specify a rectangular area to be searched with the “bounds” parameter, as follows:

Filtering by category

Every record in the Yelp database is assigned one or several categories from the set of more than 1000 recognised categories. The complete category list can be found in

The “category_filter” parameter can be used to restrict the search to a given category or categories


Searching deals

Business in the Yelp database can create deals for the users: discounts, promotions, etc. The “deals_filter” parameter can be used to limit the search to only those businesses with active deals.


 Posted by at 9:43 am

 Leave a Reply