all i need to do is to find all photosets of a user_id and then get all photos within that photoset if one clicks on the photoset using YQL
There is no built-in table yet for calling the flickr.photosets.getList
method against the Flickr API (which is what you want). There are two ways then to get at the data that you are looking for: query Flickr using the xml
YQL table, or create your own table which can abstract away the details of accessing Flickr's API.
1. Querying Flickr's API with the XML table
This approach involves knowing a few details about Flickr's REST API, how URLs are constructed to query against it, and getting a Flickr API key with which to sign your requests. These are details which YQL will often abstract away so that you don't need to care about them, but more about that later.
The approach here is to use the XML table which, when queried with a specially crafted URL and a path to the results that we want, will return the photosets that you want. Below, we'll query using my API key (to save you getting your own, though that would be a good idea) and ask for the photosets from a developer evangelist who works at Yahoo (I had to choose someone, his Flickr was the first that came to mind).
select * from xml
where url="http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=9aae7ac1770fdd8027b7aec220ae6400&user_id=11414938@N00"
and itemPath="rsp.photosets.photoset"
(Try this query in the YQL console)
The XML structure returned from that (along with the usual YQL stuff) looks like the snippet below (unless you're returning JSON, which will contain the same information just not in XML format).
<photoset farm="5" id="72157624272957243" photos="16"
primary="4751612752" secret="b799dcf7d6" server="4139" videos="0">
<title>Mozilla Add-Ons</title>
<description/>
</photoset>
<photoset farm="5" id="72157624375645496" photos="83"
primary="4741533835" secret="f6e66e4aef" server="4122" videos="0">
<title>Carter Steam Fair in Clissold Park</title>
<description/>
</photoset>
<photoset farm="5" id="72157624250084729" photos="27"
primary="4741892180" secret="c7001a3307" server="4141" videos="0">
<title>Stokey</title>
<description>Stuff happening in Stoke Newington in London</description>
</photoset>
You're then free to do with that result whatever you want. Since this question is more about querying for that specific piece of information from Flickr than how to use YQL, I'll leave out the details of using this in your programming language of choice and working with the results. Start a new question if you don't know about that sort of thing.
Earlier, I said there was another way.
2. Make a custom flickr.photosets.getList table
The details of constructing a bespoke table to query against would go a little beyond the scope of a reasonable answer here: to read up on the basics, and the fine details, head on over to the YQL documentation on this subject at http://developer.yahoo.com/yql/guide/yql-creating-opentables-chapter.html
The table itself would be pretty basic and will not do anything much more than the raw query above; the benefit is just that the details are hidden away. So, I'll show the table first and then how to use it.
The table is an XML document describing how to talk to Flickr's flickr.photosets.getList
method
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<sampleQuery>select * from {table} where user_id="11414938@N00"</sampleQuery>
<description>Retrieve the photosets belonging to the specified user.</description>
<documentationURL>http://www.flickr.com/services/api/flickr.photosets.getList.html</documentationURL>
<author>Peter Cowburn</author>
</meta>
<bindings>
<select itemPath="rsp.photosets.photoset" produces="XML">
<urls>
<url env="all">http://api.flickr.com/services/rest/?method=flickr.photosets.getList</url>
</urls>
<inputs>
<key id="user_id" type="xs:string" paramType="query" />
<key id="api_key" type="xs:string" const="true" private="true" paramType="query" default="9aae7ac1770fdd8027b7aec220ae6400"/>
</inputs>
</select>
</bindings>
</table>
To use this custom table, you would need to host it online somewhere that YQL can see it. I've uploaded it to Yahoo!'s storage which is why the URL (store://…
) might look a little odd.
And now onto the bit you've been waiting for: something of use to you!
How to use our custom table
use "store://github.com/flickr/photosets/getList" as photosets;
select * from photosets where user_id="11414938@N00"
(Try this query in the YQL console)
Conclusion
The above (just the last query, since I made the table for you already) is all that you need to get a list of a Flickr user's photosets. Simply:
use "store://github.com/flickr/photosets/getList" as photosets;
select * from photosets where user_id="11414938@N00"
And finally, to get the photos belonging to a set there is already a built-in table named flickr.photosets.photos
so you don't even need to use
a custom table:
select * from flickr.photosets.photos where photoset_id='72157624272957243'