Jump to content

Get weather information from yahooapis


mstdmstdd

Recommended Posts

  Hello,
I want ot get weather information from yahooapis and I do like

$BASE_URL = "http://query.yahooapis.com/v1/public/yql";
$yql_query = 'select wind from weather.forecast where woeid in (select woeid from geo.places(1) where text="chicago, il")';
$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";
// 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);

I got this sample from
https://developer.yahoo.com/weather/#php

It works ok for location I set in current time, what I did not find if this API gives possibility get data in next hours(days) ?
If yes, please give ref ti this description...

Also I created Consumer Key and Secret for my account, but in this example I do not use it...


Thanks!

Link to comment
Share on other sites

Their "database" structure doesn't seem to be documented anywhere, so judging by the examples: no, they don't provide an hourly forecast. At least not through that API.

 

By the way, this code is much simpler than yours:

$BASE_URL = "http://query.yahooapis.com/v1/public/yql";
$yql_query = 'select wind from weather.forecast where woeid in (select woeid from geo.places(1) where text="chicago, il")';
$phpObj = json_decode(file_get_contents($BASE_URL . "?" . http_build_query([
	"q" => $yql_query,
	"format" => "json"
])));
var_dump($phpObj);
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.