Jump to content
Sign in to follow this  
mstdmstdd

Get weather information from yahooapis

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!

Share this post


Link to post
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);

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • 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.