0

I am having problems with google weather api I have been using this script http://komunitasweb.com/2009/09/showing-the-weather-with-php-and-google-weather-api/ for sometime now but earlier I got this error:

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

Can anyone help me thank you

My code:

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

John Slegers
  • 45,213
  • 22
  • 199
  • 169
Brian
  • 1
  • 2
  • See the source you tag is mismatching means the tag is not closing or closing at the improper place – Shakti Singh Apr 06 '11 at 15:13
  • Hello thank you for your reply but what do you mean by mismatching I added by code above can you see what I'm doing wrong, I just don't know whats wrong the demo in http://komunitasweb.com/2009/09/showing-the-weather-with-php-and-google-weather-api/ is working fine but when I copy paste it in my hosting it just gives me errors – Brian Apr 06 '11 at 16:27
  • For some reason it's fix itself I'm clueless to what happened – Brian Apr 06 '11 at 16:51
  • now it's broken again I don't know what's causing this problem – Brian Apr 06 '11 at 18:20

1 Answers1

1

Apparently Google introduced Captcha to their Weather API. It will work one, two or three times, but after few request from the same server it will ask to reproduce Captcha. Something that your plugin isn't able to do.

I'm not aware of the way to get around this, so it looks like we will have to find another weather API to use. If I'm wrong please do correct me, it would be helpful.

Caching results from Google Weather might also help. 1 request in 15 or 30 minutes should be acceptable, no?

ip00
  • 11
  • 2