我发现雅虎的天气预报非常有用。
我可以从雅虎得到每小时一次的天气请求here。
如何使用Yahoo API调用http://weather.yahooapis.com/forecastrss?w=2502265来请求上述每小时一次的天气报告
This is the documentation I found。
发布于 2013-04-25 19:50:54
您可以使用要使用的编程语言的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上找到许多其他的替代方法
发布于 2017-12-22 04:42:19
雅虎天气Api似乎不支持每小时预报,只有几个参数你可以控制,如(woeid)或(lat,long)中的位置和温度单位(u或f),请参阅雅虎查询语言的here。
您可以使用其他接口的AccuWeather查看每小时详情。
https://stackoverflow.com/questions/16213242
复制相似问题