php谷歌天气api查询
从google api检索数据时遇到问题。当我运行代码时,它只返回一个空白页,而不是xml数组的打印输出。代码如下:php谷歌天气api查询,php,google-weather-api,Php,Google Weather Api,从google api检索数据时遇到问题。当我运行代码时,它只返回一个空白页,而不是xml数组的打印输出。代码如下: $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,eng
$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);
$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=英国伦敦”);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$data=curl\u exec($ch);
卷曲关闭($ch);
回声“;
打印(数据);
我认为问题在于您使用的是POST方法,而不是GET方法
像这样试试
希望有帮助:)
编辑:是的,您必须进行一些额外的解析才能从XML字符串中获取数据不是XML数组,只是普通字符串。您需要一些额外的东西来将这些字符串解析为XML。Google weather API于2012年关闭->感谢您的帮助。非常感谢。
$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);