0

Google Weather APIに問題があります。このスクリプトhttp://komunitasweb.com/2009/09/showing-the-weather-with-php-and-google-weather-api/をしばらく使用していますが、以前はこのエラーが発生しました:

警告:simplexml_load_file()[function.simplexml-load-file]://www.google.com/ig/api?weather=bermuda:2:パーサーエラー:タグの開始と終了の不一致:メタ行1と/homeのHEAD 3行目の/webmx04/public_html/weather/widgetlive1.php

警告:simplexml_load_file()[function.simplexml-load-file]:3023行目の/home/webmx04/public_html/weather/widgetlive1.phpに移動しました

警告:simplexml_load_file()[function.simplexml-load-file]:^3行目の/home/webmx04/public_html/weather/widgetlive1.php

警告:simplexml_load_file()[function.simplexml-load-file]://www.google.com/ig/api?weather=bermuda:6:パーサーエラー:タグの開始と終了の不一致:HEAD行1と/homeのHTML 3行目の/webmx04/public_html/weather/widgetlive1.php

警告:simplexml_load_file()[function.simplexml-load-file]:3行目の/home/webmx04/public_html/weather/widgetlive1.phpにあります

警告:simplexml_load_file()[function.simplexml-load-file]:^3行目の/home/webmx04/public_html/weather/widgetlive1.php

警告:simplexml_load_file()[function.simplexml-load-file]://www.google.com/ig/api?weather=bermuda:7:パーサーエラー:/ home/webmx04のタグHTML行1のデータが途中で終了しました3行目の/public_html/weather/widgetlive1.php

警告:simplexml_load_file()[function.simplexml-load-file]:3行目の/home/webmx04/public_html/weather/widgetlive1.phpにあります

警告:simplexml_load_file()[function.simplexml-load-file]:^3行目の/home/webmx04/public_html/weather/widgetlive1.php

致命的なエラー:4行目の/home/webmx04/public_html/weather/widgetlive1.phpにある非オブジェクトのメンバー関数xpath()を呼び出す

誰か助けてくれませんか

私のコード:

<?
$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>

4

1 に答える 1

1

どうやらGoogleはCaptchaをWeatherAPIに導入したようです。1回、2回、または3回動作しますが、同じサーバーからのいくつかの要求の後、キャプチャを再現するように要求されます。プラグインで実行できないこと。

これを回避する方法がわからないため、使用する別の天気APIを見つける必要があるようです。私が間違っている場合は、私を訂正してください、それは役に立ちます。

GoogleWeatherからの結果のキャッシュも役立つ場合があります。15分または30分で1回のリクエストを受け入れる必要がありますね。

于 2012-08-08T13:30:55.393 に答える