-1

I'm having trouble retrieving data from the google api. When I run the code, it only returns a blank page and not a printout of the xml array. Here is the code:

$url="http://www.google.com/ig/api";

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "?weather=london,england");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

$data = curl_exec($ch); 

curl_close($ch); 


echo "<pre>";
print_r($data); 
John Conde
  • 217,595
  • 99
  • 455
  • 496
user615099
  • 115
  • 2
  • 12
  • Is not XML array, just normal string. You need something extra to parse these string into XML – ajreal Dec 06 '11 at 12:53
  • **The Google weather API was shut down in 2012** -> http://stackoverflow.com/questions/12145820/google-weather-api-gone/35943521 – John Slegers Mar 11 '16 at 15:58

1 Answers1

1

I think that the problem is that you use POST method, and not the GET Try like this

$url="http://www.google.com/ig/api?weather=london,england";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

$data = curl_exec($ch); 

curl_close($ch); 

Hope it helps :)

EDIT: And yes, you have to do some extra parsing to get the data from the XML string

Mirko Akov
  • 2,357
  • 19
  • 19