Yelp Fusion API Wrapper
A PHP Client wrapper for Yelp's Fusion API, (*1)
, (*2)
Yelp's Fusion API allows you to get the best local business information and user reviews of over million businesses in 32 countries., (*3)
This PHP client wrapper for Yelp's Fusion API makes it dead simple. Query the API using key/value pairs to pass along search parameters, and recieve a stdClass object to work with., (*4)
Installation
Require this package with composer using the following command:
composer require thevaliantway/yelp-api
, (*5)
## Authentication
Yelp's Fusion API uses OAuth2 for Authentication. Use the bearerRequest()
method to retrieve an access token., (*6)
$id = YELP_ID
$secret = YELP_SECRET
$yelpCreds = TVW\Yelp::bearerRequest($id, $secret);
On success, the method will return an object containing the following:, (*7)
Name |
Type |
Description |
access_token |
string |
The access token which you'll use to access Yelp Fusion API endpoints. |
token_type |
int |
The access token type. Always returns Bearer. |
expires_in |
int |
Represents the number of seconds after which this access token will expire. Right now it's always 15552000, which is 180 days. |
Access tokens are valid for 180 days, so a caching strategy for issued tokens suggested., (*8)
Once a valid token has been issued, you'll be able to work with the methods below., (*9)
Business Search
Returns up to 1000 businesses based on the provided search criteria. Each API call is limited to a maximum of 50 results, so use the offset
parameter to access results beyond the initial 50 returned., (*10)
The following example will query the API for the 5 closest restaurants within 500 meters of zip code 10001, sorted by distance., (*11)
// parameters for testing
$searchParams = [
"location" => "10001",
"radius" => "500",
"sort_by" => "distance",
"categories" => "restaurants",
"limit" => 5
];
$yelpFusion = new Yelp(API_TOKEN);
$results = $yelpFusion->searchBusiness($testParams);
You can use the id returned for a business with the getBusiness()
method to retrieve detailed information., (*12)
Additional search parameters, along with detail on the API's response, may be found at https://www.yelp.com/developers/documentation/v3/business_search, (*13)
Phone Search
Returns a list of businesses based on the provided phone number. It is possible for more than one businesses having the same phone number (for example, chain stores with the same +1 800 phone number)., (*14)
The following example will query the API for businesses with "+12127527470" as the listed phone number., (*15)
$yelpFusion = new Yelp(API_TOKEN);
$results = $yelpFusion->searchPhone("+12127527470");
Note: The phone number used for searching must start with "+" and include the country code., (*16)
Detail on the API's response may be found at https://www.yelp.com/developers/documentation/v3/business_search_phone, (*17)
Transaction Search
Returns a list of businesses which support certain transactions., (*18)
The following example will query the API for businesses that deliver to the specified coordinates:, (*19)
$transactionParams = [
"latitude" => "40.730610",
"longitude" => "-73.935242"
];
$yelpFusion = new Yelp(API_TOKEN);
$result = $yelpFusion->searchTransaction("delivery", $transactionParams);
Detail on the API's response may be found at https://www.yelp.com/developers/documentation/v3/transactions_search, (*20)
Autocomplete
Returns autocomplete suggestions for search keywords, businesses and categories, based on the input text., (*21)
The following example queries the API for autocomplete suggestions using "atomic" for the specified coordinates:, (*22)
$autoCompleteParams = [
"text" => "atomic",
"latitude" => "40.730610",
"longitude" => "-73.935242"
];
$yelpFusion = new Yelp(API_TOKEN);
$results = $yelpFusion->autoComplete($autoCompleteParams);
Detail on the API's response may be found at https://www.yelp.com/developers/documentation/v3/autocomplete, (*23)
Business Details and Reviews
Returns the detailed information or up to 3 reviews of a business. A valid business id is required, and may be obtained via the business, phone, transaction, or autocomplete searches., (*24)
The following example will query the API for detailed information on Blue Hill:, (*25)
$yelpFusion = new Yelp(API_TOKEN);
$result = $yelpFusion->getDetails("details", blue-hill-new-york");
The following example will query the API for reviews on Blue Hill:, (*26)
$yelpFusion = new Yelp(API_TOKEN);
$result = $yelpFusion->getDetails("reviews", blue-hill-new-york");
Detail on the API's responses may be found at, (*27)
Support
Please open an issue for support., (*28)
Contributing
Please contribute using Github Flow. Create a branch, add commits, and open a pull request., (*29)
License
This is free software distributed under the terms of the MIT license., (*30)
About Valiant Technology
Valiant Technology is a Managed Service Provider, focused on the creative and hospitality industries. Our customers include ad agencies, PR firms, app and web developers, TV/Film producers, fashion designers, restaurants and retail. And yes, we also provide support to non-creative firms, provided they enjoy our culture and "click" with our team. Learn more at http://thevaliantway.com., (*31)