首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何调用Yahoo每小时天气预报API?

如何调用Yahoo每小时天气预报API?
EN

Stack Overflow用户
提问于 2013-04-25 19:13:44
回答 2查看 12.3K关注 0票数 2

我发现雅虎的天气预报非常有用。

我可以从雅虎得到每小时一次的天气请求here

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

This is the documentation I found

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-25 19:50:54

您可以使用要使用的编程语言的REST API来执行此操作。我将给出Java的例子。(类似的事情也适用于其他语言。)‘

代码语言:javascript
复制
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上找到许多其他的替代方法

票数 -1
EN

Stack Overflow用户

发布于 2017-12-22 04:42:19

雅虎天气Api似乎不支持每小时预报,只有几个参数你可以控制,如(woeid)或(lat,long)中的位置和温度单位(u或f),请参阅雅虎查询语言的here

您可以使用其他接口的AccuWeather查看每小时详情。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16213242

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档