Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8357449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:28:43+00:00 2026-06-09T10:28:43+00:00

I decided to pull information from Google’s Weather API – The code I’m using

  • 0

I decided to pull information from Google’s Weather API – The code I’m using below works fine.

            XmlDocument widge = new XmlDocument();
            widge.Load("https://www.google.com/ig/api?weather=Brisbane/dET7zIp38kGFSFJeOpWUZS3-");
            var weathlist = widge.GetElementsByTagName("current_conditions");
            foreach (XmlNode node in weathlist)
            {

                City.Text = ("Brisbane");
                CurCond.Text = (node.SelectSingleNode("condition").Attributes["data"].Value);
                Wimage.ImageUrl = ("http://www.google.com/" + node.SelectSingleNode("icon").Attributes["data"].Value);
                Temp.Text = (node.SelectSingleNode("temp_c").Attributes["data"].Value + "°C");
        }
     }

As I said, I am able to pull the required data from the XML file and display it, however if the page is refreshed or a current session is still active, I receive the following error:

WebException was unhandled by user code – The remote server returned
an error: 403 Forbidden Exception.

I’m wondering whether this could be to do with some kind of access limitation put on access to that particular XML file?

Further research and adaptation of suggestions

As stated below, this is by no means best practice, but I’ve included the catch I now use for the exception. I run this code on Page_Load so I just do a post-back to the page. I haven’t noticed any problems since. Performance wise I’m not overly concerned – I haven’t noticed any increase in load time and this solution is temporary due to the fact this is all for testing purposes. I’m still in the process of using Yahoo’s Weather API.

        try
        {
            XmlDocument widge = new XmlDocument();
            widge.Load("https://www.google.com/ig/api?weather=Brisbane/dET7zIp38kGFSFJeOpWUZS3-");
            var list2 = widge.GetElementsByTagName("current_conditions");
            foreach (XmlNode node in list2)
            {

                City.Text = ("Brisbane");
                CurCond.Text = (node.SelectSingleNode("condition").Attributes["data"].Value);
                Wimage.ImageUrl = ("http://www.google.com/" + node.SelectSingleNode("icon").Attributes["data"].Value);
                Temp.Text = (node.SelectSingleNode("temp_c").Attributes["data"].Value + "°C");

            }
        }
        catch (WebException exp)
        {
            if (exp.Status == WebExceptionStatus.ProtocolError &&
                exp.Response != null)
            {
                var webres = (HttpWebResponse)exp.Response;
                if (webres.StatusCode == HttpStatusCode.Forbidden)
                {
                    Response.Redirect(ithwidgedev.aspx);
                }

            }
        }

Google article illustrating API error handling

Google API Handle Errors

Thanks to:

https://stackoverflow.com/a/12011819/1302173 (Catch 403 and recall)

https://stackoverflow.com/a/11883388/1302173 (Error Handling and General Google API info)

https://stackoverflow.com/a/12000806/1302173 (Response Handling/json caching – Future plans)

Alternative

I found this great open source alternative recently

OpenWeatherMap – Free weather data and forecast API

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:28:46+00:00Added an answer on June 9, 2026 at 10:28 am

    This is related to a change / outage of the service. See: http://status-dashboard.com/32226/47728

    enter image description here

    I have been using Google’s Weather API for over a year to feed a phone server so that the PolyCom phones receive a weather page. It has run error free for over a year. As of August 7th 2012 there have been frequent intermittent 403 errors.

    I make a hit of the service once per hour (As has always been the case) so I don’t think frequency of request is the issue. More likely the intermittent nature of the 403 is related to the partial roll-out of a configuration change or a CDN change at Google.

    The Google Weather API isn’t really a published API. It was an internal service apparently designed for use on iGoogle so the level of support is uncertain. I tweeted googleapis yesterday and received no response.

    It may be better to switch to a promoted weather API such as:
    WUnderground Weather or
    Yahoo Weather.

    I have added the following ‘unless defined’ error handling perl code myself yesterday to cope with this but if the problem persists I will switch to a more fully supported service:

    my $url = "http://www.google.com/ig/api?weather=" . $ZipCode ;
    
    my $tpp = XML::TreePP->new();
    my $tree = $tpp->parsehttp( GET => $url );
    
    my $city = $tree->{xml_api_reply}->{weather}->{forecast_information}->{city}->{"-data"};
    
    unless (defined($city)) {
        print "The weather service is currently unavailable. \n";
        open (MYFILE, '>/home/swarmp/public_html/status/polyweather.xhtml');
        print MYFILE qq(<?xml version="1.0" encoding="utf-8"?>\n);
        print MYFILE qq(<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "xhtml11.dtd">\n);
        print MYFILE qq(<html xmlns="http://www.w3.org/1999/xhtml">\n);
        print MYFILE qq(<head><title>Weather is Unavailable!</title></head>\n);
        print MYFILE qq(<body>\n);
        print MYFILE qq(<p>\n);
        print MYFILE qq(The weather service is currently unavailable from the data vendor.\n);
        print MYFILE qq(</p>\n);
        print MYFILE qq(</body>\n);
        print MYFILE qq(</html>\n);
        close MYFILE;
        exit(0);
    }...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pulling json from the Instagram API using a curl request. I want to
I decided to have a go at PDO. The function below should move a
I recently decided to port my indexing engine from sphinx to solr. Having used
I'm using the WML function providelocalinfo to put location information into Short Messages send
I have been requested by a client to pull the latest posts from their
So I'm working on a form, and I'm using PHP to pull an array
Problem: I need to pull data from auth logs for approx. 30 locations. The
I have comma delimited strings I need to pull values from. The problem is
Here is the database-design http://www.flickr.com/photos/michaelstitt/6077647604/in/photostream/ that I decided upon -- using the help from
I am writing a lot of JQuery code in a page and have decided

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.