简体   繁体   中英

yahoo weather api returns null

I'm working on yahoo weather system but yahoo api returns null result.

This code I get from here: 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);

When I enter this url in browser then it returns required result.

valid result return weather system correctly

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=

Yahoo weather APIs are being retired. According to 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.

I think you are missing "near the WHERE text=

Replace

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

with

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

if you get Curl error: SSL certificate problem: unable to get local issuer certificate. then use

curl_setopt($session, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM