我发现雅虎天气预报最有帮助。
我可以从雅虎获得每小时的天气请求。
如何使用 Yahoo API 调用http://weather.yahooapis.com/forecastrss?w=2502265为上述每小时天气报告发出 API 请求?
我发现雅虎天气预报最有帮助。
我可以从雅虎获得每小时的天气请求。
如何使用 Yahoo API 调用http://weather.yahooapis.com/forecastrss?w=2502265为上述每小时天气报告发出 API 请求?
Yahoo Weather Api 似乎不支持每小时预报,只有几个参数可以控制,例如 (woeid) 或 (lat, long) 中的位置和温度单位 (u 或 f),请参阅此处获取 yahoo 查询语。
您可以使用其他 api 的AccuWeather获取每小时的详细信息。
您可以使用您想要使用的编程语言的 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找到许多其他替代方法