Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

yelp api help 1

Status
Not open for further replies.

darryncooke

Technical User
May 6, 2009
308
US
So I have this code but its not pulling anything.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$yelpstring = file_get_contents(" wont give this up that easily", true);

$obj = json_decode($yelpstring);

foreach($obj->businesses as $business):
echo $business->name."<br/>";
endforeach;
?>
</body>
</html>

I mean its pretty straight forward but nothing. Also how do i use json decode to decode an array within an array?

For example the array businesses has another array within it called reviews. how will i do to reviews what i have done to businesses?

Darryn Cooke
| The New Orange County Graphic designer and Marketing and Advertising Consultant
| Marketing and Advertising blog
 
Run printr() on the received variable and it's Json decoded versionto get abides of its shape.
Can't help with why the variable is not populated unless you tell us about errors that you are getting. If you are not seeing errors then make sure that error reporting and error display are turned on. If you are still not getting anything then it's not a php problem.
 
have you turned on error reporting and error display?

Code:
ini_set('display_errors', true);
error_reporting(E_ALL);
(at the top of your script).

if so, the problem is in the api call. which we cannot help with unless there is a test key that you can share.
 
oh. i would also say that i don't understand the 'true' at the end of your file_get_contents (). it should be firing an error because it is meaningless. which makes me believe that you do not have error display/reporting turned on.

remove the second argument from the function call. it should then work from a php perspective.
 
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /hermes/bosweb/web258/b2583/glo.deeceeuci70/moodinblue/yelp.php on line 13

Warning: file_get_contents( [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /hermes/bosweb/web258/b2583/glo.deeceeuci70/moodinblue/yelp.php on line 13

Notice: Trying to get property of non-object in /hermes/bosweb/web258/b2583/glo.deeceeuci70/moodinblue/yelp.php on line 17

Warning: Invalid argument supplied for foreach() in /hermes/bosweb/web258/b2583/glo.deeceeuci70/moodinblue/yelp.php on line 17

Darryn Cooke
| The New Orange County Graphic designer and Marketing and Advertising Consultant
| Marketing and Advertising blog
 
the first line says it all. your server is set up to prohibit external url access. if you cannot change your server config you will have to use curl instead. if you cannot use curl then you will have to change hosts.

curl alternative looks briefly like this

Code:
$url = '[URL unfurl="true"]http://api.yelp.com/phone_search?phone=9496730570&amp;ywsid=i[/URL] wont give this up that easily';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
$response = curl_exec($ch);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top