雅虎天气 API WOEID 检索

2022-08-30 15:08:39

我正在创建一个应用程序(PHP),该应用程序从免费的RSS源中获取雅虎天气数据,并根据从RSS源检索到的数据将其与颜色十六进制相关联。我遇到的问题是找到一种方法来获取位置代码或WOEID,而无需手动操作。

Yahoos API 会发回 RSS 源,只要您提供 WOEID ->http://weather.yahooapis.com/forecastrss?w=4097

有没有一种合乎道德的方式来做到这一点?我的初学者知识告诉我,我必须写一个脚本,使用这个术语搜索雅虎并获取第一个WOEID,但我认为雅虎不希望脚本这样做,而且它似乎过于复杂了......如果没有,是否有任何替代API可以使我更轻松地做到这一点?

谢谢!


答案 1

为什么不直接使用Yahoo! GeoPlanet服务将一个地方解析为WOEID?或者使用YQL服务通过其表访问GeoPlanet?

http://where.yahooapis.com/v1/places.q('Barrie CA')?appid=[yourappidhere]

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22Barrie%20CA%22&format=xml

无需刮擦。

干杯

G

(披露;我在Yahoo!工作,是WOEIDs和GeoPlanet背后的团队的一员)


答案 2

我从以下位置获得了一些有用的信息:http://developer.yahoo.com/geo/geoplanet/

http://developer.yahoo.com/geo/geoplanet/guide/api-reference.html#api-countries

  1. 找到一个重要地标的WOEID:http://where.yahooapis.com/v1/places.q('sydney%20opera%20house')?appid=[yourappidhere]

  2. 将 WOEID 解析到某个地方:http://where.yahooapis.com/v1/place/2507854?appid=[yourappidhere]

  3. 查找特定地点的 WOEID:http://where.yahooapis.com/v1/places.q('northfield%20mn%20usa')?appid=[yourappidhere]

  4. 获取与给定地点匹配的 WOAID 范围,按最可能的顺序排序:http://where.yahooapis.com/v1/places.q('springfield');start=0;count=5?appid=[yourappidhere]

  5. 找到给定WOEID的父母(并返回详细记录):http://where.yahooapis.com/v1/place/638242/parent?select=long&appid=[yourappidhere]

  6. 以特定语言(如果存在)返回给定WOEID的地名:http://where.yahooapis.com/v1/places.q('usa')?lang=fr&appid=[yourappidhere]

  7. 要以 JSON 格式获取地点的表示形式:http://where.yahooapis.com/v1/place/2487956?format=json&appid=[yourappidhere]

  8. 要获取与特定 WOEID 相邻的地理区域列表:http://where.yahooapis.com/v1/place/12795711/neighbors?appid=[yourappidhere]


推荐