New Slideshare Slideshows YQL Table


I’m in the process of building out a new personal site which will use YQL to pull in all of my recent photos, slideshows, events, etc. from the different sites I use to build out the content of the website. This task has led me to create a new YQL table to wrap the slideshow RSS feed to display the slideshows of a user.

 

This new table is available at http://github.com/yql/yql-tables/blob/master/slideshare/slideshare.slideshows.xml for the time being until it becomes available in the community tables in the YQL Console. You can test the new table out in the console by using the USE clause as displayed here. The feed that will be available to a developer using this table will look like the below:

 

 

- Jonathan LeBlanc

  • Share/Bookmark


Building Flickr URLs from YQL flickr.photos.search Results


After having to build out the URL structure from the Yahoo! Query Language (YQL) results returned by the flickr.photos.search table yet again, I’ve decided to actually document how to generate Flickr URLs using the results returned from YQL.

 

When we use YQL the structure of results returned by a Flickr photo search contains all of the pieces that you will need to generate a whole series of author and photo links with Flickr, but it does not go the extra step of returning these links back to you. For instance, if we run a Flickr photo search query within the YQL (e.g. http://developer.yahoo.com/yql/console/?q=select%20*%20from%20flickr.photos.search%20where%20has_geo%3D%22true%22%20and%20text%3D%22san%20francisco%22) the result set that is returned back from YQL from flickr.photos.search looks something like this:



    
true
        
        445
        444
        5275
    
    










    

 

Now let’s take a look at how to do something with those data pieces.

 

Generating an image source
Using the farm, server, id and secret parameters from the result set, we can generate an image source that will display the searched image. The structure of the source using these parameters will look like:

<img src='http://farm{$farm}.static.flickr.com/{$server}/{$id}_{$secret}.jpg' alt='{$title}' />

 

Generating a link back to the photo page on Flickr
Under the terms of service, all photos that you use from Flickr will need to link back to the Flickr photo page of the owner. Using the owner and id parameters from the result set, we can generate a link back to the Flickr page for the searched image. Building upon the image source that we built above, we can wrap the image with a link that sends the user back to the original image page on Flickr:

<a href='http://www.flickr.com/photos/{$owner}/{$id}' target='_blank'>
<img src='http://farm{$farm}.static.flickr.com/{$server}/{$id}_{$secret}.jpg' alt='{$title}' />
</a>

 

Generating a link back to the photo owner’s profile
It’s always nice to provide a credit for the photo by linking back to the root profile of the photo owner (instead of just the photo page that we saw above). By using the owner variable in the photo return data, we can easily create a link back to the profile of the photo owner and give him/her credit. Building upon our current linked photo example, we can add in one more piece to do this:

<a href='http://www.flickr.com/photos/{$owner}/{$id}' target='_blank'>
<img src='http://farm{$farm}.static.flickr.com/{$server}/{$id}_{$secret}.jpg' alt='{$title}' />
</a>
<a href="http://www.flickr.com/photos/{$owner}" target="_blank">Photo Owner</a>

 

Now let’s see how to code a script in PHP that will output the photos wrapped in links back to their original sources (as seen in the second example above listed as “Generating a link back to the photo page on Flickr”). What we do in the code below is generate the YQL query URL, capture the results into a variable using simplexml_load_file, then pass the array of photos through to a function to build the HTML for us.

<?php
$yql_url = 'http://query.yahooapis.com/v1/public/yql?';
$query = 'SELECT * FROM flickr.photos.search WHERE has_geo="true" AND text="san francisco"';
$query_url = $yql_url . 'q=' . urlencode($query) . '&format=xml';

$photos = simplexml_load_file($query_url);
$result = build_photos($photos->results->photo);
echo $result;

function build_photos($photos){
    $html = '';
    if (count($photos) > 0){
        foreach ($photos as $photo){
            $html .= "<a href='http://www.flickr.com/photos/{$photo['owner']}/{$photo['id']}' target='_blank'><img src='http://farm4.static.flickr.com/{$photo['server']}/{$photo['id']}_{$photo['secret']}.jpg' width='75' height='75' alt='{$photo['title']}' /></a>";
        }
    } else {
        $html .= 'No Photos Found';
    }
    return $html;
}
?>

These are easy ways of displaying Flickr photos and links based on the results returned from the flickr.photo.search table in YQL. They’re simple examples but worth documenting so that you don’t need to go through the hassle of pieces the URL structures together on your next project.

 

- Jonathan LeBlanc

  • Share/Bookmark


Browser MVC with YUI and YQL


 

In July of 2009 I gave a talk at a JavaScript meetup called Bayjax. This talk covered the topic of Browser MVC using YQL and YUI as the technology backbone and went into an overview of YQL.

 

URL’s for the tabs can be found at http://speakerrate.com/talks/1281-coupling-yql-and-yui-to-build-dynamic-visualization-widgets

 

A slide breakdown of the content discussed in this talk may be found at http://www.slideshare.net/jcleblanc/bayjax-july-2009-browser-mvc-with-yql-yui

  • Share/Bookmark


Helpful YQL Queries


While I’ve been working with the Yahoo! Query Language, there are several queries that I have put together for different tasks which I wished to share.  These queries showcase some of the screen scraping and external file aggregation abilities of the platform.  All of these queries may be tested on the YQL console to see the output results. Below are a few of these queries:

 

Digg story headlines – Captures all page headlines

 

Flickr get photos in a set – Get number of photos

 

Flickr – Get photos on page 1 (60 per page)

 

Flickr – Get photos on page 2

 

Twitter – Get recent user tweets

 

Timezone from lat/lon – Get timezone data based on lat/lon

 

Flickr Connection Friend’s Photos – Capture photos for locations of user’s connections

 

Maps by Placemaker URL – Returns maps for all places found at a URL

 

- Jonathan LeBlanc

  • Share/Bookmark


Coupling YUI and YQL to build JavaScript Widgets


One of the tasks that I have been working on lately has been to create front-end JavaScript visualizations of YQL query results. What I ended up doing was creating a generic JavaScript include that uses YUI for some of the data parsing. Using this method, I set up a system where a developer could just include this JavaScript file, set up a few configuration variables and then a nice visualization widget would be displayed.

 

You can see a sample of the widget by going here: http://www.liquidmediatech.com/php_widget/yql_php_widget.html

 

Here’s what the full configuration for the widget looks like:

<!-- widget file include -->
<script type="text/javascript" src="yql_php_widget.js"></script>

<style>
div#badgeContainer{ padding:0 5px; font:bold 14px arial,helvetica,sans-serif; color:#f0f0f0; }
div#badgeContainer img{ float:left; margin-right:8px; margin-top:3px; border:0; }
div#badgeContainer span{ font-weight:normal; font-size:12px; }
div#badgeContainer a{ text-decoration:none; color:#f0f0f0; }
div#badgeContainer a:hover{ text-decoration:underline; }
div#widgetContainer{ background-color:#474747; width:300px; padding:5px 0; }
div#widgetContainer div.iconBox{ width:17px; height:16px; float:left; }
div#widgetContainer div.widgetRow{ padding:5px; background-color:#509cd1; border:1px solid #8fc5eb; margin:5px; overflow:hidden; }
div#widgetContainer div.widgetRow, div#widgetContainer div.widgetRow a{ color:#f0f0f0; font:11px arial,helvetica,sans-serif; }
div#widgetContainer div.widgetRow a{ font-weight:bold; }
</style>

<div id="widgetContainer"></div>

<script type="text/javascript">
var config = {'badge':true, 'num_results':10, 'debug':true};
var format = '<div class="widgetRow"><a href="{link}" target="_blank"><div style="background-color:#fff;border:2px solid #8fc5eb;width:20px;height:20px;float:left;margin-right:4px;"><img src="{loc_iconURL}" width="16" height="16" style="border:0;padding:2px;" /></div></a> <a href="{link}" target="_blank">{loc_longForm}</a><br />' + '{lastUpdated}</div>';
var yqlQuery = 'select lastUpdated, link, loc_iconURL, loc_longForm, profile_nickname, profile_profileUrl, publishedTime from social.updates where guid=me | sort(field="lastUpdated") | reverse()';
var insertEl = 'widgetContainer';
yqlWidget.push(yqlQuery, config, format, insertEl);
yqlWidget.render();
</script>

I have full documentation and the code base to set up this example on my github account at http://github.com/jonleblanc/yql-utilities/tree/master.

 

For a more in depth explanation of what was built out with this tool take a look at my post on the YUI blog at http://www.yuiblog.com/blog/2009/06/17/yui-and-yql/

 

- Jonathan LeBlanc

  • Share/Bookmark