tahrin_aziz
tahrin_aziz

Reputation: 29

I wanna use Yahoo weather API. but the previous API has become unauthorized. how can i use yahoo weather RSS in my C# code?

I wanna use Yahoo weather API. but the previous API has become unauthorized. how can I use yahoo weather RSS in my C# code ? I have been trying to use this:

https://query.yahooapis.com/v1/public/yql?q=select%20%20from%20weather.forecast%20where%20woeid%3D1915035%20and%20u%3D%27c%27&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

but it seems to return Null to my XmlNode

Upvotes: 0

Views: 238

Answers (1)

tahrin_aziz
tahrin_aziz

Reputation: 29

private void GetWeather()
{
    string query = String.Format("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D1915035%20and%20u%3D%27c%27&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");
    XmlDocument wData = new XmlDocument();
    wData.Load(query);

    XmlNamespaceManager manager = new XmlNamespaceManager(wData.NameTable);
    manager.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");

    XmlNode channel = wData.SelectSingleNode("rss").SelectSingleNode("channel");//exception here
    XmlNodeList nodes = wData.SelectNodes("rss/channel/item/yweather:forecast", manager);

    Temperature = channel.SelectSingleNode("item").SelectSingleNode("yweather:condition", manager).Attributes["temp"].Value;
    Condition = channel.SelectSingleNode("item").SelectSingleNode("yweather:condition", manager).Attributes["text"].Value;
    Humidity = channel.SelectSingleNode("yweather:atmosphere", manager).Attributes["humidity"].Value;
    WindSpeed = channel.SelectSingleNode("yweather:wind", manager).Attributes["speed"].Value;
    Town = channel.SelectSingleNode("yweather:location", manager).Attributes["city"].Value;
    TPCond = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["text"].Value;
    TPHigh = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["high"].Value;
    TPLow = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["low"].Value;        
}

Upvotes: 0

Related Questions