PHP:Yahoo Weather Api使用file_get_content获取空结果

时间:2017-01-04 05:47:33

标签: php yahoo-weather-api

我正在从我的网页进行ajax调用,以获取JSON格式的getWeather.php页面的响应。有时候我会得到结果,但大多数时候我都没有。但每当我浏览此链接时,它总是以JSON格式给我结果。我在getWeather.php中做错了吗?

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%27lahore%27)%20AND%20u%3D%27c%27&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=

getWeather.php实施:

<?php
$city = $_GET['city'];

echo file_get_contents("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%27".$city."%27)%20AND%20u%3D%27c%27&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");


?>
  

{&#34;查询&#34; {&#34;计数&#34;:0,&#34;创建&#34;:&#34; 2017-01-03T04:50:27Z&#34; &#34;朗&#34;:&#34;的en-US&#34;&#34;结果&#34;:空}}

1 个答案:

答案 0 :(得分:2)

雅虎天气API有问题。你可以查看雅虎; https://developer.yahoo.com/weather/在自己的应用上遇到同样的问题。