I want to try and figure out how to take the data that is output from the Yelp Business API 2.0 and actually choose what bits I want to echo, add styling, so on and so forth.
Here is the basic query:
<?php
require_once ('lib/OAuth.php');
$unsigned_url = "http://api.yelp.com/v2/business/the-waterboy-sacramento";
// Set your keys here
$consumer_key = 'mykey';
$consumer_secret = 'mysecret';
$token = 'mytoken';
$token_secret = 'mytokensecret';
$token = new OAuthToken($token, $token_secret);
$consumer = new OAuthConsumer($consumer_key, $consumer_secret);
$signature_method = new OAuthSignatureMethod_HMAC_SHA1();
$oauthrequest = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $unsigned_url);
$oauthrequest->sign_request($signature_method, $consumer, $token);
$signed_url = $oauthrequest->to_url();
$ch = curl_init($signed_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$response = json_decode($data);
$json_string = file_get_contents($signed_url);
$result = json_decode($json_string);
// Print it for debugging
echo '<pre>';
print_r($result);
echo '</pre>';
?>
In the area where the data is being printed, how would I modify this for example, to return only the business name? Or only the business address? Or both items, each encased in its own div?
Is there a simple method such as:
echo $business_name;
echo $business_address;
I am basically just trying to figure out how to take the deluge of output information, which is just in a basic text format without any formatting whatsoever by default, and actually select what I want to display, give each bit a div with its own class, so I can style it and make it pretty.
Currently, print_r
returns:
stdClass Object
(
[is_claimed] =>
[rating] => 4
[mobile_url] => http://m.yelp.com/biz/the-waterboy-sacramento
[rating_img_url] => http://s3-media4.fl.yelpcdn.com/assets/2/www/img/c2f3dd9799a5/ico/stars/v1/stars_4.png
[review_count] => 485
[name] => The Waterboy
[snippet_image_url] => http://s3-media2.fl.yelpcdn.com/photo/yd0M2_X6-S7mg_jFT4KtnQ/ms.jpg
[rating_img_url_small] => http://s3-media4.fl.yelpcdn.com/assets/2/www/img/f62a5be2f902/ico/stars/v1/stars_small_4.png
[url] => http://www.yelp.com/biz/the-waterboy-sacramento
[menu_date_updated] => 1387494198
[reviews] => Array
(
[0] => stdClass Object
(
[rating] => 5
[excerpt] => DEFINITE REPEAT
First time here. Host greeted us, explained restaurant style, etc. Very nice gentleman, and very knowledgable.
Our server was...
[time_created] => 1406526888
[rating_image_url] => http://s3-media1.fl.yelpcdn.com/assets/2/www/img/f1def11e4e79/ico/stars/v1/stars_5.png
[rating_image_small_url] => http://s3-media1.fl.yelpcdn.com/assets/2/www/img/c7623205d5cd/ico/stars/v1/stars_small_5.png
[user] => stdClass Object
(
[image_url] => http://s3-media2.fl.yelpcdn.com/photo/yd0M2_X6-S7mg_jFT4KtnQ/ms.jpg
[id] => HRxSv183RfenlVyFWX4gCw
[name] => Randy S.
)
[rating_image_large_url] => http://s3-media3.fl.yelpcdn.com/assets/2/www/img/22affc4e6c38/ico/stars/v1/stars_large_5.png
[id] => OxfuTiiznTQpwaY6zBa7UQ
)
)
[phone] => 9164989891
[snippet_text] => DEFINITE REPEAT
First time here. Host greeted us, explained restaurant style, etc. Very nice gentleman, and very knowledgable.
Our server was...
[image_url] => http://s3-media4.fl.yelpcdn.com/bphoto/Y4kSp64IBG2M4CGrENIegA/ms.jpg
[categories] => Array
(
[0] => Array
(
[0] => French
[1] => french
)
[1] => Array
(
[0] => Italian
[1] => italian
)
)
[display_phone] => +1-916-498-9891
[rating_img_url_large] => http://s3-media2.fl.yelpcdn.com/assets/2/www/img/ccf2b76faa2c/ico/stars/v1/stars_large_4.png
[menu_provider] => single_platform
[id] => the-waterboy-sacramento
[is_closed] =>
[location] => stdClass Object
(
[city] => Sacramento
[display_address] => Array
(
[0] => 2000 Capitol Ave
[1] => Downtown
[2] => Sacramento, CA 95811
)
[geo_accuracy] => 9
[neighborhoods] => Array
(
[0] => Downtown
[1] => Midtown
)
[postal_code] => 95811
[country_code] => US
[address] => Array
(
[0] => 2000 Capitol Ave
)
[coordinate] => stdClass Object
(
[latitude] => 38.573153
[longitude] => -121.481208
)
[state_code] => CA
)
)