简单的雅虎天气 Api 不起作用 [英] Simple Yahoo Weather Api Not Working

查看:30
本文介绍了简单的雅虎天气 Api 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个简单的代码,其中包含一个 yahoo api 代码来获取我所在城市的天气并将其放在我的网页上,但是,我刚刚读到 yahoo 公共 api 不再工作,我不知道怎么做我让这段代码工作,我有一个雅虎帐户,我创建了一个 api,从这里开始我不知道如何继续.如果有人可以帮助我,这是代码:

I was using a simple code which includes a yahoo api code to get just the weather from my city and put in on my web page, however, i just read that yahoo public api is no longer working and i dont know how can a i get this code to work, i have a yahoo account, i created an api and i dont know how to proceed since here. If somebody can help me this is the code:

<?php
/*Clima*/
if(isset($_POST['zipcode']) && is_numeric($_POST['zipcode'])){
    $zipcode = $_POST['zipcode'];
}else{
    $zipcode = 'ARMA0056';
}
$result = file_get_contents('http://weather.yahooapis.com/forecastrss?p=' . $zipcode . '&u=c');
$xml = simplexml_load_string($result);

//echo htmlspecialchars($result, ENT_QUOTES, 'UTF-8');

$xml->registerXPathNamespace('yweather', 'http://xml.weather.yahoo.com/ns/rss/1.0');
$location = $xml->channel->xpath('yweather:location');

if(!empty($location)){
    foreach($xml->channel->item as $item){
        $current = $item->xpath('yweather:condition');
        $forecast = $item->xpath('yweather:forecast');
        $current = $current[0];
        $clima = <<<END
           <span>{$current['temp']}&deg;C</span>

END;
    }
}else{
    $clima = '<h1>No results found, please try a different zip code.</h1>';
}
/*Clima*/
?> 

推荐答案

只需将 http://weather.yahooapis.com 替换为 http://xml.weather.yahoo.com.归功于 https://forum.rainmeter.net/viewtopic.php?f=13&t=23010

just replace http://weather.yahooapis.com with http://xml.weather.yahoo.com. credits to https://forum.rainmeter.net/viewtopic.php?f=13&t=23010

这篇关于简单的雅虎天气 Api 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆