Skip to content

Latest commit

 

History

History
60 lines (45 loc) · 1.73 KB

API-GUIDE-v2.md

File metadata and controls

60 lines (45 loc) · 1.73 KB

Yelp PHP Client - v2

Create client explicitly

$client = new \Stevenmaguire\Yelp\v2\Client(array(
    'consumerKey' => 'YOUR COSUMER KEY',
    'consumerSecret' => 'YOUR CONSUMER SECRET',
    'token' => 'YOUR TOKEN',
    'tokenSecret' => 'YOUR TOKEN SECRET',
    'apiHost' => 'api.yelp.com' // Optional, default 'api.yelp.com'
));

Search by keyword and location

$results = $client->search(array('term' => 'Sushi', 'location' => 'Chicago, IL'));

Search by phone number

$results = $client->searchByPhone(array('phone' => '867-5309'));

Locate details for a specific business by Yelp business id

$business = $client->getBusiness('union-chicago-3');

You may include action links in your results by passing additional parameters with your request.

$resultsWithActionLinks = $client->getBusiness('union-chicago-3', [
    'actionLinks' => true
]);

Configure defaults

$client->setDefaultLocation('Chicago, IL')  // default location for all searches if location not provided
    ->setDefaultTerm('Sushi')               // default keyword for all searches if term not provided
    ->setSearchLimit(20);                   // number of records to return

Exceptions

If the API request results in an Http error, the client will throw a \Stevenmaguire\Yelp\Exception\HttpException that includes the response body, as a string, from the Yelp API.

try {
    $business = $client->getBusiness('union-chicago-3');
} catch (\Stevenmaguire\Yelp\Exception\HttpException $e) {
    $responseBody = $e->getResponseBody(); // string from Http request
    $responseBodyObject = json_decode($responseBody);
}