Yahoo! Query Language (YQL)
04-07-2011, 06:50 AM, (This post was last modified: 04-07-2011, 07:12 AM by Zach.)
#1
Yahoo! Query Language (YQL)
I thought this was great. Yahoo! Query Language lets you access many web APIs using a (mostly) standardized SQL-like language. Currently, you can access:
  • Yahoo! Search Results
  • Facebook
  • Twitter
  • GeoIP
  • and a bunch more.
It's really easy to use, too. You can get results in JSON or XML, whichever you prefer to work with, via a simple file_get_contents() in PHP or a similar function in any other language.
Recently, I used it for the "Recent Forum Posts" and "Latest News" sections on the new NiftyHost.us website. YQL has a 'feed' table that parses RSS and Atom feeds for you quickly and easily. This allowed me to set up those sections in a matter of minutes.
Hi! I'm Zach, and I founded NiftyHost. If you need anything, just PM me! :)
Reply
04-07-2011, 07:13 AM,
#2
RE: Yahoo! Query Language (YQL)
Thanks, I'll be using that. Would love a tutorial or some proper/easy examples :)
With love,
HiddenKnowledge
A.k.a. Yoruichi Shihouin

If you have any questions, feel free to contact me trough email or pm. :)
Reply
04-07-2011, 07:33 AM, (This post was last modified: 04-07-2011, 07:35 AM by Zach.)
#3
RE: Yahoo! Query Language (YQL)
Well, here's the code I use in my functions files to make it work in the first place:
PHP Code:
<?php
    
function yql_query($q) {
        
// simple wrapper function to send a YQL query,
        // get the results, and return it as a raw array.
        
$q objectToArray(json_decode(file_get_contents('http://query.yahooapis.com/v1/public/yql?format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q=' urlencode($q))));
        return 
$q;
    }
    function 
objectToArray($d) {
        if (
is_object($d)) {
            
// Gets the properties of the given object
            // with get_object_vars function
            
$d get_object_vars($d);
        }
 
        if (
is_array($d)) {
            
/*
            * Return array converted to object
            * Using __FUNCTION__ (Magic constant)
            * for recursive call
            */
            
return array_map(__FUNCTION__$d);
        }
        else {
            
// Return array
            
return $d;
        }
    }
?>
Then, we can use yql_query($query) to submit a query and get the results and stuff as an array.
To experiment with YQL and discover new tables, use the YQL Console at http://developer.yahoo.com/yql/console/. You can also use that to find the structure of the results which yql_query would return from each table.
Here's an example of using YQL to get the latest news from the NiftyHost Forums and to display it as an unordered list:
PHP Code:
<?php
echo '<ul>';
$latest yql_query('select * from feed where url="http://www.niftyhost.us/support/syndication.php?fid=4&limit=3"');
foreach (
$latest['query']['results']['item'] as $tidbit) {
echo 
'<li><a href="' $tidbit['link'] . '">' $tidbit['title'] . '</a><br>
<span class="small">' 
date('F j, Y, g:i a',strtotime($tidbit['pubDate'])) . '</span></li>';
}
echo 
'</ul>';
?>
Hi! I'm Zach, and I founded NiftyHost. If you need anything, just PM me! :)
Reply
04-07-2011, 10:09 PM,
#4
RE: Yahoo! Query Language (YQL)
Thanks :)
With love,
HiddenKnowledge
A.k.a. Yoruichi Shihouin

If you have any questions, feel free to contact me trough email or pm. :)
Reply
04-09-2011, 04:13 AM,
#5
RE: Yahoo! Query Language (YQL)
Awesom i dint knew you can access facebook via YQL
Reply
04-09-2011, 10:10 AM,
#6
RE: Yahoo! Query Language (YQL)
Facebook, YouTube, and a whole lot more.
Hi! I'm Zach, and I founded NiftyHost. If you need anything, just PM me! :)
Reply
04-11-2011, 06:39 AM,
#7
RE: Yahoo! Query Language (YQL)
can you also access MTV via it or any other music sites?
Reply
04-16-2011, 10:22 PM,
#8
RE: Yahoo! Query Language (YQL)
The only music thing it can access at this point in time appears to be Yahoo! Music. You can look around in the console and play with tables.
Hi! I'm Zach, and I founded NiftyHost. If you need anything, just PM me! :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What coding language do you use? HiddenKnowledge 63 16,085 06-15-2012, 12:10 PM
Last Post: RichardGv

Forum Jump: