【问题标题】:PHP: Yahoo Weather Api getting empty result with file_get_contentPHP:Yahoo Weather Api 使用 file_get_content 获得空结果
【发布时间】:2017-05-18 08:10:21
【问题描述】:

我正在从我的网页进行 ajax 调用,以从 getWeather.php 页面以 JSON 格式获取响应。有时我得到结果,但大多数情况下我没有。但是每当我浏览这个链接时,它总是给我 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=");


?>

{"query":{"count":0,"created":"2017-01-03T04:50:27Z","lang":"en-US","re​​sults":null}}

【问题讨论】:

  • 确保城市不为空,否则此代码可以正常工作。
  • 我什至在查询中写了城市名称进行测试,但有时我得到结果,有时我没有。

标签: php yahoo-weather-api


【解决方案1】:

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

【讨论】:

  • 是的,就是这个原因。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多