微软的天气API非常类似于谷歌(现在似乎完全死了)。我已将我的一个应用程序转换为其Feed,但我无法找到所有可能的天气状况列表。
Google的天气API已经很好地记录了这一点,但我找不到MSN天气API的条件列表。
FWIW,使用MSN获取数据的示例URL是:
http://weather.service.msn.com/data.aspx?weadegreetype=F&culture=en-US&weasearchstr=Chicago,IL (服务不再可用(2016年1月))
任何人都可以了解可能的情况吗?我需要它们,以便我可以将条件文本转换为图标。
答案 0 :(得分:17)
我决定采用稍微不同的路线,根据XML提供的图标( skycode 和 skycodeday )计算条件。
以下列出了我的想法。希望从Google的天气API迁移对其他人有所帮助:
答案 1 :(得分:5)
这是我的功能,可以轻松将您的Google API代码转换为MSN API:
function skycode2image ($skycode)
{
$daynight = "na";
$skycodes = array (
0 => 'thunderstorm',
1 => 'thunderstorm',
2 => 'thunderstorm',
3 => 'thunderstorm',
4 => 'thunderstorm',
5 => 'rain_snow',
6 => 'sleet',
7 => 'rain_snow',
8 => 'icy',
9 => 'icy',
10 => 'rain_snow',
11 => 'showers',
12 => 'rain',
13 => 'flurries',
14 => 'snow',
15 => 'snow',
16 => 'snow',
17 => 'thunderstorm',
18 => 'showers',
19 => 'dust',
20 => 'fog',
21 => 'haze',
22 => 'haze',
23 => 'windy',
24 => 'windy',
25 => 'icy',
26 => 'cloudy',
27 => 'mostly_cloudy',
28 => 'mostly_cloudy',
29 => 'partly_cloudy',
30 => 'partly_cloudy',
31 => 'sunny',
32 => 'sunny',
33 => 'mostly_sunny',
34 => 'mostly_sunny',
35 => 'thunderstorm',
36 => 'hot',
37 => 'chance_of_tstorm',
38 => 'chance_of_tstorm',
39 => 'chance_of_rain',
40 => 'showers',
41 - 'chance_of_snow',
42 => 'snow',
43 => 'snow',
44 => 'na',
45 => 'chance_of_rain',
46 => 'chance_of_snow',
47 => 'chance_of_tstorm');
$condition = $skycodes[$skycode];
if (in_array($skycode,array(27,29,31,33,31,45,46,47))) $daynight = 'night';
if (in_array($skycode,array(28,30,32,34,36,37,38,39,41))) $daynight = 'day';
return array($condition,$daynight);
}
答案 2 :(得分:2)
似乎每当微软遇到问题时都会发生很多错误信息。 我今天正在测试MSN Weather API;它确实回来了;并且每小时返回天气数据。
我刚才做了以下[可能非标准]查询: “http://weather.service.msn.com/data.aspx?weasearchstr=ny,NY&culture=en-US&weadegreetype=C&src=msn”
它确实返回了所要求的内容:
<weatherdata xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><weather weatherlocationcode="wc:USNY0309" weatherlocationname="New York, NY" url="http://a.msn.com/54/en-US/ct40.782,-73.832?ctsrc=msn" imagerelativeurl="http://blob.weather.microsoft.com/static/weather4/en-us/" degreetype="C" provider="Foreca" attribution="http://www.foreca.com/" attribution2="Foreca" lat="40.782" long="-73.832" timezone="-5" alert="" entityid="10109777" encodedlocationname="New+York%2C+NY"><current temperature="4" skycode="29" skytext="Partly Cloudy" date="2016-02-07" observationtime="18:00:00" observationpoint="New York, NY" feelslike="2" humidity="62" winddisplay="9 km/h East" day="Sunday" shortday="Sun" windspeed="9 km/h" /><forecast low="-3" high="5" skycodeday="31" skytextday="Clear" date="2016-02-06" day="Saturday" shortday="Sat" precip="" /><forecast low="1" high="7" skycodeday="28" skytextday="Mostly Cloudy" date="2016-02-07" day="Sunday" shortday="Sun" precip="10" /><forecast low="-3" high="3" skycodeday="16" skytextday="Snow" date="2016-02-08" day="Monday" shortday="Mon" precip="90" /><forecast low="0" high="1" skycodeday="30" skytextday="Partly Sunny" date="2016-02-09" day="Tuesday" shortday="Tue" precip="90" /><forecast low="-2" high="5" skycodeday="28" skytextday="Mostly Cloudy" date="2016-02-10" day="Wednesday" shortday="Wed" precip="50" /><toolbar timewindow="60" minversion="1.0.1965.0" /></weather><weather weatherlocationcode="wc:USNY0996" weatherlocationname="New York, NY" url="http://a.msn.com/54/en-US/ct40.714,-74.006?ctsrc=msn" imagerelativeurl="http://blob.weather.microsoft.com/static/weather4/en-us/" degreetype="C" provider="Foreca" attribution="http://www.foreca.com/" attribution2="Foreca" lat="40.714" long="-74.006" timezone="-5" alert="" entityid="23164" encodedlocationname="New+York%2C+NY"><current temperature="5" skycode="29" skytext="Partly Cloudy" date="2016-02-07" observationtime="18:00:00" observationpoint="New York, NY" feelslike="4" humidity="58" winddisplay="7 km/h East" day="Sunday" shortday="Sun" windspeed="7 km/h" /><forecast low="-7" high="4" skycodeday="31" skytextday="Clear" date="2016-02-06" day="Saturday" shortday="Sat" precip="" /><forecast low="1" high="7" skycodeday="28" skytextday="Mostly Cloudy" date="2016-02-07" day="Sunday" shortday="Sun" precip="10" /><forecast low="-2" high="3" skycodeday="16" skytextday="Snow" date="2016-02-08" day="Monday" shortday="Mon" precip="80" /><forecast low="-1" high="1" skycodeday="30" skytextday="Partly Sunny" date="2016-02-09" day="Tuesday" shortday="Tue" precip="80" /><forecast low="-3" high="5" skycodeday="30" skytextday="Partly Sunny" date="2016-02-10" day="Wednesday" shortday="Wed" precip="50" /><toolbar timewindow="60" minversion="1.0.1965.0" /></weather></weatherdata>
答案 3 :(得分:1)
这是2016年4月,看起来微软天气数据仍然存在:Washington state weather data(链接与OP的帖子中显示的不同 - 现已停止使用)。
链接中的“wealocations”参数对于每个天气采集点都是不同的;例如,“USWA0367”适用于华盛顿州雷德蒙德。您可以从here.
获取天气位置代码答案 4 :(得分:0)
我们谨此通知您,Microsoft Weather API将不再可供下载,并将于2015年4月15日停止使用,这意味着它将不再提供天气数据。因此,请从当前使用它的任何产品或应用中删除Microsoft Weather API。
如果您有兴趣获得备用天气API,以下是可能能够满足您需求的外部提供商列表:
http://api.accuweather.com/
http://www.wunderground.com/weather/api/d/pricing.html
https://developer.forecast.io/
免责声明:Microsoft和Microsoft Weather不以任何方式与上述任何公司挂钩或关联。
谢谢 微软天气团队