2011-04-06 54 views
0

我有我一直在使用这个脚本http://komunitasweb.com/2009/09/showing-the-weather-with-php-and-google-weather-api/了一段时间,现在与谷歌的天气API的问题,但早些时候,我得到这个错误:谷歌的天气API问题

Warning: simplexml_load_file() [function.simplexml-load-file]: //www.google.com/ig/api?weather=bermuda:2: parser error : Opening and ending tag mismatch: meta line 1 and HEAD in /home/webmx04/public_html/weather/widgetlive1.php on line 3

Warning: simplexml_load_file() [function.simplexml-load-file]: 302 Moved in /home/webmx04/public_html/weather/widgetlive1.php on line 3

Warning: simplexml_load_file() [function.simplexml-load-file]:^in /home/webmx04/public_html/weather/widgetlive1.php on line 3

Warning: simplexml_load_file() [function.simplexml-load-file]: //www.google.com/ig/api?weather=bermuda:6: parser error : Opening and ending tag mismatch: HEAD line 1 and HTML in /home/webmx04/public_html/weather/widgetlive1.php on line 3

Warning: simplexml_load_file() [function.simplexml-load-file]: in /home/webmx04/public_html/weather/widgetlive1.php on line 3

Warning: simplexml_load_file() [function.simplexml-load-file]:^in /home/webmx04/public_html/weather/widgetlive1.php on line 3

Warning: simplexml_load_file() [function.simplexml-load-file]: //www.google.com/ig/api?weather=bermuda:7: parser error : Premature end of data in tag HTML line 1 in /home/webmx04/public_html/weather/widgetlive1.php on line 3

Warning: simplexml_load_file() [function.simplexml-load-file]: in /home/webmx04/public_html/weather/widgetlive1.php on line 3

Warning: simplexml_load_file() [function.simplexml-load-file]:^in /home/webmx04/public_html/weather/widgetlive1.php on line 3

Fatal error: Call to a member function xpath() on a non-object in /home/webmx04/public_html/weather/widgetlive1.php on line 4

谁能帮我谢谢

我代码:

<? 
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=bermuda'); 
$information = $xml->xpath("/xml_api_reply/weather/forecast_information"); 
$current = $xml->xpath("/xml_api_reply/weather/current_conditions"); 
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions"); 
?> 
<html> 
<head> 
    <title>Google Weather API</title> 
</head> 
<body> 
<div id="widget-wrapper"><!-- start widget-wrapper--> 
<div class="weather"><!-- start weather--> 

     <h2><a href="/section/weather" title="More on Weather" target="_top">Current Weather</a></h2> 
      <a href="/section/weather" target="_top"><img src="<?= 'http://www.rgbdahosting.com' . $current[0]->icon['data']?>" alt="More on Weather"?></a> 
      <span class="condition"> 
      <a href="/section/weather" title="More on Weather" target="_top"><H4><?= $current[0]->temp_f['data'] ?>&deg;F</H4> 

      <p><?= $current[0]->condition['data'] ?></p></a> 
      </span> 
     </div><!-- end weather--> 

</div> <!-- end widget-wrapper--> 
</body> 

+0

查看源代码不匹配意味着代码未在关闭或关闭的不当位置 – 2011-04-06 15:13:30

+0

您好,感谢您的回复,但是您通过上述代码添加的不匹配的含义,您能看到我在做什么错误,我只是不知道什么是错的演示在http://komunitasweb.com/2009/09/showing-the-weather-with-php-and-google-weather-api/工作正常,但当我复制粘贴它在我的托管它只是给了我错误 – Brian 2011-04-06 16:27:50

+0

由于某种原因它是修复自己我很无知发生了什么 – Brian 2011-04-06 16:51:57

回答

1

显然,谷歌推出将Captcha添加到他们的Weather API中。它将工作一次,两次或三次,但在几次来自同一台服务器的请求后,它会要求重现验证码。你的插件无法做到的事情。

我不知道如何解决这个问题,所以看起来我们将不得不寻找其他的天气API来使用。如果我错了,请纠正我,这将是有益的。

来自Google Weather的缓存结果可能也有帮助。 1或15或30分钟内的要求应该是可以接受的,不是吗?