雅虎天气 api returns 空

yahoo weather api returns null

我正在使用雅虎天气系统,但雅虎 api return 的结果为空。

我从这里得到的代码:https://developer.yahoo.com/weather/#php

$BASE_URL = "http://query.yahooapis.com/v1/public/yql";    
$yql_query = 'select * from weather.forecast where woeid in (SELECT woeid FROM geo.places WHERE text=('.$time->latitude.','.$time->longitude.'))';
$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json&diagnostics=true&callback=";
// 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);

当我在浏览器中输入此 url 时,它 return 需要结果。

有效结果return天气系统正确

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(SELECT%20woeid%20FROM%20geo.places%20WHERE%20text=%22(40.7141667,-74.0063889)%22)&format=json&diagnostics=true&callback=

我认为你在 WHERE text=

附近丢失了 "

替换

$yql_query = 'select * from weather.forecast where woeid in (SELECT woeid FROM geo.places WHERE text=('.$time->latitude.','.$time->longitude.'))';

$yql_query = 'select * from weather.forecast where woeid in (SELECT woeid FROM geo.places WHERE text="(' . $time->latitude . ',' . $time->longitude . ')")';

如果您收到 Curl 错误:SSL 证书问题:无法获取本地颁发者证书。然后使用

curl_setopt($session, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);

雅虎天气 API 即将停用。 根据https://developer.yahoo.com/weather ...

Important EOL Notice

The weather.yahooapis.com and fallback endpoints are being retired. We will no longer be providing free Weather API services for public users. Please contact yahoo-weather-ydn-api@oath.com if you have any questions, comments, or interest in supported paid services.