我正在雅虎天气系统工作,但是yahoo api会返回null结果。
我从这里得到的代码: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);
当我在浏览器中输入此网址时,它会返回所需的结果。
有效的结果返回天气系统正确
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=
答案 0 :(得分:1)
雅虎天气API已淘汰。 根据{{3}} ...
重要的停产通知
weather.yahooapis.com和后备端点已淘汰。我们 将不再为公众提供免费的Weather API服务 用户。如果您有任何疑问,请联系yahoo-weather-ydn-api@oath.com 问题,评论或对支持的付费服务的兴趣。
答案 1 :(得分:0)
我认为你错过了#34;在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);