troubleshooting Question

Organize data from Google news API using php

Avatar of Pedro Chagas
Pedro ChagasFlag for Portugal asked on
JavaScriptPHP
3 Comments2 Solutions520 ViewsLast Modified:
Hi E's, I need to organize some data from a query of google news API, and I want to list or organize and put some of that received information into a php array. In this case I want put the publishers of the news into array.
I try this code:
<?
$jsonString = file_get_contents("https://ajax.googleapis.com/ajax/services/search/news?v=1.0&q=algarve%20turismo&hl=pt&ned=pt-PT_pt&callback=foo");
$json = json_decode($jsonString);
$links = array();
foreach($json->foo as $item) {
  $links[] = $item->publisher;
}
?>
<pre>
<?
print_r($links);
?>
But the result is:
Warning: Invalid argument supplied for foreach() in /home/pedro/public_html/biblioteca/tutoriais/1140/exemplo.php on line 5
Array
(
)

What I do wrong?

The best regards, JC
ASKER CERTIFIED SOLUTION
John Kawakami

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros