【问题标题】:Yahoo Weather WebService雅虎天气网络服务
【发布时间】:2011-01-11 17:45:31
【问题描述】:

我正在尝试使用 Yahoo 查询语言通过 Yahoo Weather 获取一些天气信息。

由于我住在法国尼斯市,因此以下查询返回错误:

select * from weather.forecast where location='Nice'

我已经协调好经纬度,如何将它们交给 YQL 以返回天气信息?这项服务是全球性的还是仅适用于美国?

【问题讨论】:

    标签: webservice-client yql yahoo-weather-api


    【解决方案1】:

    您应该改用另一个 YQL 数据表。我试过这个查询,它工作正常:

    SELECT * FROM weather.bylocation WHERE location='Nice' AND unit="c"
    

    This is the YQL console

    我已经添加了unit="c" 以获取摄氏温度,假设您需要它。如果不是,请使用“f”。

    weather.bylocation 表内部使用以下两个东西:

    1. 查找位置的“在地球上的位置标识符 (woeid),
    2. 然后查找此 ID 的天气。

    查看下表的内部结构:

        <execute><![CDATA[
          default xml namespace ='http://where.yahooapis.com/v1/schema.rng'; 
          var x = y.query('select woeid from geo.places(1) where text="'+location+'"');
          var s = x.results;
          var woeid = s..woeid;
          var weather = y.rest('http://weather.yahooapis.com/forecastrss?w='+woeid+'&u='+unit).get().response;
          response.object = <weather>{weather}</weather>;
        ]]></execute>
    

    关于您关于使用经纬度协调的第二个问题: 我不知道你是否可以使用它们,但也许你现在甚至不再需要它了,对吧?

    也不错:

    http://developer.yahoo.com/weather/

    http://developer.yahoo.com/geo/geoplanet/guide/concepts.html

    【讨论】:

    • 如果你想在使用 weather.forecast 表时将单位更改为摄氏度,你需要使用 AND 运算符添加此条件:u="c" 即:select * from weather.forecast where woeid= 823015 和 u="c"
    • 此查询不再有效。收到此错误:Please provide valid credentials。随着网站阻止用户代理或需要 OAuth,YQL 似乎变得越来越不可靠。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-06
    • 2012-08-16
    • 2013-02-09
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多