PHP code example of stevenmaguire / yelp-php

1. Go to this page and download the library: Download stevenmaguire/yelp-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stevenmaguire / yelp-php example snippets


$options = 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'
);

$client = \Stevenmaguire\Yelp\ClientFactory::makeWith(
    $options,
    \Stevenmaguire\Yelp\Version::TWO
);

$options = array(
    'accessToken' => 'YOUR ACCESS TOKEN', // Required, unless apiKey is provided
    'apiHost' => 'api.yelp.com', // Optional, default 'api.yelp.com',
    'apiKey' => 'YOUR ACCESS TOKEN', // Required, unless accessToken is provided
);

$client = \Stevenmaguire\Yelp\ClientFactory::makeWith(
    $options,
    \Stevenmaguire\Yelp\Version::THREE
);

// $latestRateLimit will be null if an http request hasn't been successfully completed.
$latestRateLimit = $client->getRateLimit();

// The maximum number of calls you can make per day
$latestDailyLimit = $latestRateLimit->dailyLimit;

// The number of calls remaining within the current day
$latestRemaining = $latestRateLimit->remaining;

// The time at which the current rate limiting window will expire as an ISO 8601 timestamp
$latestResetTime = $latestRateLimit->resetTime;

// The time at which the current rate limiting data was observed as an ISO 8601 timestamp
$latestCreatedAt = $latestRateLimit->createdAt;

$responseBody = $e->getResponseBody(); // string from Http request
$responseBodyObject = json_decode($responseBody);

$client = new \Stevenmaguire\Yelp\v3\Client(array(
    'accessToken' => $accessToken,
));

// Create a new guzzle http client
$specialHttpClient = new \GuzzleHttp\Client([
    // ... some special configuration
]);

// Update the yelp client with the new guzzle http client
// then get business data
$business = $client->setHttpClient($specialHttpClient)
    ->getBusiness('the-motel-bar-chicago');

// Create request for other yelp API resource not supported by yelp-php
$request = $client->getRequest('GET', '/v3/some-future-endpoint');

// Send that request
$response = $client->getResponse($request);

// See the contents
echo $response->getBody();

// same options for all
$options = 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'
);


// yelp-php 1.x
$client = new Stevenmaguire\Yelp\Client($options);

// yelp-php 2.x - option 1
$client = \Stevenmaguire\Yelp\ClientFactory::makeWith(
    $options,
    \Stevenmaguire\Yelp\Version::TWO
);

// yelp-php 2.x - option 2
$client = new \Stevenmaguire\Yelp\v2\Client($options);
 bash
$ composer