简单的Yahoo天气Api不工作

简单的Yahoo天气Api不工作,api,yahoo,weather,Api,Yahoo,Weather,我使用了一个简单的代码,其中包括一个雅虎api代码,以获取我所在城市的天气信息,并将其放在我的网页上,然而,我刚刚读到雅虎公共api不再工作,我不知道如何才能使此代码工作,我有一个雅虎帐户,我创建了一个api,我不知道如何从这里开始。如果有人能帮我这是代码: <?php /*Clima*/ if(isset($_POST['zipcode']) && is_numeric($_POST['zipcode'])){ $zipcode = $_POST['zipcode

我使用了一个简单的代码,其中包括一个雅虎api代码,以获取我所在城市的天气信息,并将其放在我的网页上,然而,我刚刚读到雅虎公共api不再工作,我不知道如何才能使此代码工作,我有一个雅虎帐户,我创建了一个api,我不知道如何从这里开始。如果有人能帮我这是代码:

<?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*/
?> 

雅虎最近更新了他们处理请求的方式。它过去只是通过任何连接,但现在为了使它更安全、更易于处理,他们最近选择通过OAuth1发送所有请求。使用他们在页面上提供的示例代码,通过JSON从请求中获取信息


有关更多信息,请参阅。

只需更换即可http://weather.yahooapis.com 具有http://xml.weather.yahoo.com. 归功于

xml.weather.yahoo.com是解决方案,但URL似乎不再有效。我现在使用yahoos查询从%20weather.forecast%20where%20woeid%3D2489314获取XML,即。*%20


除了添加到树中的结果之外,这似乎是相同的XML。

YAHOO更改了一些关于api的规则; 我让下面的课程为我工作。。。希望为你工作; $fcast=$phpObj->查询->结果->渠道->项目->预测;更改其他项目的此行

<?php 
date_default_timezone_set('CET');
class weatherfc{
public $result;
function weather($city){
 $BASE_URL = "http://query.yahooapis.com/v1/public/yql";
 $yql_query = 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="'.$city.'") and u="c"';
$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";
    // Make call with cURL
    $session = curl_init($yql_query_url);
    curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
    $json = curl_exec($session);
    // Convert JSON to PHP object
  $phpObj =  json_decode($json);
  //var_dump($phpObj);
    $weatherd='<div> Weather In '.$city.'<br>';
    $fcast=$phpObj->query->results->channel->item->forecast;
    foreach($fcast as $witem){
    $fdate=DateTime::createFromFormat('j M Y', $witem->date);

    $weatherd.= '<div class="days">';
    $weatherd.= '<div class="item"><div>'.$fdate->format('d.m').'&nbsp;'.$witem->day.'</div><div class="image" style="width:90px !important; height:65px !important;"><img src="http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/'.$witem->code.'d.png" width=90></div></div>';
    $weatherd.= '<div><span>'.$witem->high.'&deg;C</span>';
    $weatherd.= '<span>'.$witem->low.'°C</span></div></div>';
    };
    $this->result=$weatherd;
}

}

$h= new weatherfc;
$h->weather("Antalya,Turkey");
echo $h->result;
?>



    <style>
    .days{
    width:90px;
    font-size:12px;
    float:left;
    font-family:Arial, Helvetica, sans-serif;
    border:#999 1px dotted;
    }

</style>

我正在尝试获取windows窗体应用程序的XML请求,但无法访问第二个XML链接。例如我正在尝试访问,但它一直说它无效。请尝试使用此查询选择*from weather.forecast where woeid in选择woeid from geo.places where placetype='Zip'和text='68510'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20%28从%20geo.places%20where%20placetype%3D%27Zip%27%20和%20text%3D%2768510%27%20%29&format=xmlThis刚刚停止工作,有人知道另一种方法吗?@EricWeintraub