2013-04-25 108 views
2

我发现雅虎天气预报最有帮助。如何拨打雅虎每小时天气预报API?

我可以从雅虎获得小时天气请求here

如何使用Yahoo API调用http://weather.yahooapis.com/forecastrss?w=2502265来为上述小时天气报告提出API请求?

This is the documentation I found

+1

你想用什么工具调用RSS提要?你想显示在网页上还是在桌面应用程序(或其他)? – snumpy 2013-04-25 11:24:29

+0

开发一个web应用程序,它每小时显示天气,发现雅虎天气api最适合http://developer.yahoo.com/weather,但我也发现了一个[链接](http://in.weather.com/weather/hourByHour-INXX0104?cm_ven = yahoo_in&cm_cat = citypage&cm_ite = weather&cm_pla = hourly),我们如何让yhoo api呼叫小时天气 – anu 2013-04-25 11:28:44

+0

#yahoo-weather-api – Rolan 2017-06-21 18:26:51

回答

0

您可以使用您希望使用的编程语言的REST API。我将给出Java示例。 (类似的道理也适用于其他语言太..)”

package tests; 

import org.apache.http.*; 
import org.apache.http.client.methods.HttpGet; 
import org.apache.http.impl.client.DefaultHttpClient; 
import org.apache.http.util.EntityUtils; 

/** 
* A simple Java REST GET example using the Apache HTTP library. 
* This executes a call against the Yahoo Weather API service, which is 
* actually an RSS service (http://developer.yahoo.com/weather/). 
* 
* Try this Twitter API URL for another example (it returns JSON results): 
* http://search.twitter.com/search.json?q=%40apple 
* (see this url for more twitter info: https://dev.twitter.com/docs/using-search) 
* 
* Apache HttpClient: http://hc.apache.org/httpclient-3.x/ 
* 
*/ 
public class ApacheHttpRestClient1 { 

    public static void main(String[] args) { 
    DefaultHttpClient httpclient = new DefaultHttpClient(); 
    try { 
     // specify the host, protocol, and port 
     HttpHost target = new HttpHost("weather.yahooapis.com", 80, "http"); 

     // specify the get request 
     HttpGet getRequest = new HttpGet("/forecastrss?p=80020&u=f"); 

     System.out.println("executing request to " + target); 

     HttpResponse httpResponse = httpclient.execute(target, getRequest); 
     HttpEntity entity = httpResponse.getEntity(); 

     System.out.println("----------------------------------------"); 
     System.out.println(httpResponse.getStatusLine()); 
     Header[] headers = httpResponse.getAllHeaders(); 
     for (int i = 0; i < headers.length; i++) { 
     System.out.println(headers[i]); 
     } 
     System.out.println("----------------------------------------"); 

     if (entity != null) { 
     System.out.println(EntityUtils.toString(entity)); 
     } 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } finally { 
     // When HttpClient instance is no longer needed, 
     // shut down the connection manager to ensure 
     // immediate deallocation of all system resources 
     httpclient.getConnectionManager().shutdown(); 
    } 
    } 

有更多的方式做同样的...你可以找到http://alvinalexander.com/java/java-apache-httpclient-restful-client-examples

+0

这是一个很好的帮助光环..我在LAMP平台上我正在检查它..感谢 – anu 2013-04-25 12:01:06

+0

如果我们点击这里[链接](http://in.weather.yahoo.com/united-states/maryland/california-2373278/)在页面中只需点击小时。我们可以看到每小时的天气报告。我想知道我们如何能够像[http://weather.yahooapis.com/forecastrss?w=2442047&u=c]中的[链接](http://developer.yahoo.com/weather)一样请求forcastrss /) – anu 2013-04-26 04:22:08

+0

是的,你也可以使链接http://developer.yahoo.com/weather/#req – AurA 2013-04-26 04:34:41

0

雅虎天气阿比许多其他替代方式似乎不支持每小时预测,只有几个参数可以控制,例如(woeid)或(lat,long)中的位置和温度单位(u或f),请参阅here获取雅虎查询语言。

您可以使用其他api的AccuWeather获取每小时详细信息。