yahoo weather api returns null - php

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);

Related

How to display weather with this code

Well I will not take credit for these codes as I found it but I would appreciate if someone can help me display the weather with this following coding I will really appreciate it.
$BASE_URL = "http://query.yahooapis.com/v1/public/yql";
$yql_query = 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="sc")';
$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);
echo '<pre>';print_r($phpObj).'<pre>';
I just want this code to display the weather of a particular place with some variable which I can echo like
echo $city;
echo $temp;
something like this.
really thank you for your valuable time and kindness for helping
For Php Object:
$phpObj = json_decode($json); // converting to object
echo $phpObj->property_name;
For Php Array:
$phpArr = json_decode($json, true); // converting to array
echo $phpArr['index'];
ok i got it and sharing the codes so that it could be of use to someone who is looking for weather api
$BASE_URL = "http://query.yahooapis.com/v1/public/yql";
$yql_query = 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="sc")';
$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);
echo $phpObj->query->results->channel->location->city.' Weather <br/>';
echo 'Current: '.$phpObj->query->results->channel->item->condition->text.', ';
echo sprintf("%0.0f", ($phpObj->query->results->channel->item->condition->temp - 32) * 5 / 9).'°C <br/>';
echo $phpObj->query->results->channel->item->forecast[0]->day.': ';
echo $phpObj->query->results->channel->item->forecast[0]->text.', ';
echo '<small>'.sprintf("%0.0f", ($phpObj->query->results->channel->item->forecast[0]->low - 32) * 5 / 9).'Min°C - </small>';
echo '<small>'.sprintf("%0.0f", ($phpObj->query->results->channel->item->forecast[0]->high - 32) * 5 / 9).'Max°C </small><br/>';
echo $phpObj->query->results->channel->item->forecast[1]->day.': ';
echo $phpObj->query->results->channel->item->forecast[1]->text.', ';
echo '<small>'.sprintf("%0.0f", ($phpObj->query->results->channel->item->forecast[1]->low - 32) * 5 / 9).'Min°C - </small>';
echo '<small>'.sprintf("%0.0f", ($phpObj->query->results->channel->item->forecast[1]->high - 32) * 5 / 9).'Max°C </small><br/>';

yahoo weather API PHP authorization

In yahoo developer guide is example how to retrieve some info about weather
$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);
this example has limit 2000 request per day, to increase limits I must use API client key and secret KEY.
How I can do authorization ? It's possible in curl or ? only by OAuth 2.0

yahoo import contacts through yql giving error

I am trying to import yahoo contacts with help of YQL but stuck with a problem.
I am using approach on this link https://developer.yahoo.com/yql/guide/yql-code-examples.html#yql_php
But I got this error:
{"error":{"lang":"en-US","description":"Authentication Error. The table social.contacts requires a higher security level than is provided, you provided ANY but at least USER is expected"}}
Do I am missing something
I have run this query on yql console its showing result but nt getting results directly hitting url or with curl.
My code is :
$BASE_URL = "https://query.yahooapis.com/v1/public/yql";
// Form YQL query and build URI to YQL Web service
$yql_query = "select * from social.contacts(0, 500) where guid=me";
$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);
// Confirm that results were returned before parsing
if(!is_null($phpObj->query->results)){
// Parse results and extract data to display
foreach($phpObj->query->results->event as $event){
$events .= "<div><h2>" . $event->name . "</h2><p>";
$events .= html_entity_decode(wordwrap($event->description, 80, "<br/>"));
$events .="</p><br/>$event->venue_name<br/>$event->venue_address<br/>";
$events .="$event->venue_city, $event->venue_state_name";
$events .="<p><a href=$event->ticket_url>Buy Tickets</a></p></div>";
}
}
// No results were returned
if(empty($events)){
$events = "Sorry, no events matching $query in $location";
}
// Display results and unset the global array $_GET
echo $events;
unset($_GET);

YQL API Request Private Data Authentication Error

I am using YQL to pull some data for my yahoo fantasy football league. I have created the app and it gave me a consumer/secret key but how do I pass this information to the yahoo api to log me in? I know I have to use OAuth but I am not sure how to use the key in tandem with CURL and YQL
Here is my PHP Code:
<pre>
<?php
$BASE_URL = "https://query.yahooapis.com/v1/public/yql";
// Form YQL query and build URI to YQL Web service
$yql_query = "select * from fantasysports.leagues.standings where league_key='331.l.777400'";
$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);
?>
</pre>
and the error I get is
"Authentication Error. The table fantasysports.leagues.standings
requires a higher security level than is provided, you provided ANY
but at least USER is expected"

Bing Image Search API results exipres after some time

I am implementing Bing Image Search API in php. I know that Bing API has been changed and now we have to involve that windows azure marketplace thing in-order to use the Bing Image Search API.
I have done that, which means i have opted for a free Bing Search Api subscription which gives me around 5000 transaction per month. Its going all good but the thing is the result which is being fetched is tend to get expired after say 1 month.
Here is the code i am using :
$key = "cricket";
// Replace this value with your account key
$accountKey = 'WEGUEed3yF9CI6ZzVblKD0HoMRG3/rOELkCda9VYsuk=';
$ServiceRootURL = 'https://api.datamarket.azure.com/Bing/Search/';
$WebSearchURL = $ServiceRootURL . 'Image?$format=json&Query=';
$request = $WebSearchURL . urlencode( '\'' . $key . '\'');
$process = curl_init($request);
curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($process, CURLOPT_USERPWD, $accountKey . ":" . $accountKey);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($process);
$jsonobj = json_decode($response);
echo('<ul ID="resultList">');
foreach($jsonobj->d->results as $value)
{
echo('<li class="resultlistitem"><a href="' . $value->MediaURL . '">');
echo('<img src="' . $value->Thumbnail->MediaUrl. '"></li>');
}
echo("</ul>");
On running this program i am getting the results, I am getting the image source. But the thing is the image source doesn't seems to be a real image source i mean the URL is something like this :
http://ts4.mm.bing.net/th?id=HN.608026386931518543&pid=15.1
Also this link is expires after a month or so .... Initally i was able to see the image when clicking on the link but it expired after a month and now i can only see a greyish camera with a cross on it which means that the image source has been expired i guess.
If you can let me how can i restrict this thing and also is anything needs to done on the windows azure market place end to get things working for me .
Any help will be appreciated
Thanks
Fix for original images.
On the line 22, where are interpreted received and parsed JSON data
echo('<li class="resultlistitem"><a href="' . $value->MediaURL . '">');
there is a mistake from Bing.
You can just replace
$value->MediaURL for $value->MediaUrl
and you can get acquire access to original image.

Categories