forked from nickwhynot/whynotv5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yelpbus.php
54 lines (38 loc) · 1.59 KB
/
yelpbus.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
function yelpbus($id){
//
// From http://non-diligent.com/articles/yelp-apiv2-php-example/
//
//$category = "term=" . $category . "&";
// Enter the path that the oauth library is in relation to the php file
require_once ('lib/OAuth.php');
// For example, request business with id 'the-waterboy-sacramento'
$unsigned_url = "http://api.yelp.com/v2/business/" . $id;
// For examaple, search for 'tacos' in 'sf'
//$unsigned_url = "http://api.yelp.com/v2/search?sort=2&radius_filter=2500&" . $category . "ll=" . $latitude . "," . $longitude . "";
// Set your keys here
$consumer_key = "ho0pNfHtbRimd-vSaTtykQ";
$consumer_secret = "2fyaNEjynrq03hiAEsNj8-FhNRU";
$token = "6bH4Xmcu2y4C5bBNGyijjUzY1Z1qo1zW";
$token_secret = "ZaZCsL2Jm3mRXUovY99E_PYUE3s";
// Token object built using the OAuth library
$token = new OAuthToken($token, $token_secret);
// Consumer object built using the OAuth library
$consumer = new OAuthConsumer($consumer_key, $consumer_secret);
// Yelp uses HMAC SHA1 encoding
$signature_method = new OAuthSignatureMethod_HMAC_SHA1();
// Build OAuth Request using the OAuth PHP library. Uses the consumer and token object created above.
$oauthrequest = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $unsigned_url);
// Sign the request
$oauthrequest->sign_request($signature_method, $consumer, $token);
// Get the signed URL
$signed_url = $oauthrequest->to_url();
// Send Yelp API Call
$ch = curl_init($signed_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch); // Yelp response
curl_close($ch);
return $data;
}
?>