YUI 3.x Home -

YUI Library Examples: YQL Query: YQL Flickr Requery

YQL Query: YQL Flickr Requery

In this example, the Flickr Recent Photos YQL table is used to pull in a small set of recent Flickr images every 8 seconds.

Setting Up the Query

The easiest way to build a YQL query is by visiting the YQL Console. In this example we will be using the flickr.photos.recent table. The YQL statement that we are using looks like this:

  1. SELECT * FROM flickr.photos.recent
SELECT * FROM flickr.photos.recent

Setting Up the YUI Instance

Now we need to create our YUI instance and tell it to load the yql and node modules.

  1. YUI().use('node', 'yql')
YUI().use('node', 'yql')

Making the Query

Now that we have a YUI instance with the yql module, we can now make a query.

  1. YUI().use('node', 'yql', function(Y) {
  2.  
  3. var res = Y.one('#res'), count = 0,
  4. url = '<a href="http://flickr.com/photos/{owner}/{id}"><img src="http://static.flickr.com/{server}/{id}_{secret}_t.jpg"></a>';
  5.  
  6. var q = Y.YQL('select * from flickr.photos.recent', function(r) {
  7. count++;
  8. res.setContent('<h2>Recent Flickr Photos <em>(query #' + count + ')</em></h2>');
  9. Y.each(r.query.results.photo, function(v) {
  10. res.append(Y.Lang.sub(url, v));
  11. });
  12. });
  13. Y.later(8000, q, q.send, null, true);
  14. });
YUI().use('node', 'yql', function(Y) {
 
    var res = Y.one('#res'), count = 0,
        url = '<a href="http://flickr.com/photos/{owner}/{id}"><img src="http://static.flickr.com/{server}/{id}_{secret}_t.jpg"></a>';
 
    var q = Y.YQL('select * from flickr.photos.recent', function(r) {
        count++;
        res.setContent('<h2>Recent Flickr Photos <em>(query #' + count + ')</em></h2>');
        Y.each(r.query.results.photo, function(v) {
            res.append(Y.Lang.sub(url, v));
        });
    });
    Y.later(8000, q, q.send, null, true);
});

Copyright © 2011 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings