如何使用 YQL 获取用户的所有 flickr 照片集?
我需要做的就是找到 user_id 的所有照片集,然后如果使用 YQL 单击照片集,则获取该照片集中的所有照片
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我需要做的就是找到 user_id 的所有照片集,然后如果使用 YQL 单击照片集,则获取该照片集中的所有照片
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
目前还没有内置表可用于针对 Flickr API 调用
flickr.photosets.getList
方法(这正是您想要的)。有两种方法可以获取您要查找的数据:使用xml
YQL 表查询 Flickr,或者创建您自己的表,该表可以抽象出访问 Flickr API 的详细信息。1. 使用 XML 表查询 Flickr 的 API
此方法涉及了解有关 Flickr REST API 的一些详细信息、如何构建 URL 来查询它,以及获取用于签署请求的 Flickr API 密钥。这些是 YQL 通常会抽象出来的细节,这样您就不需要关心它们,但稍后会详细介绍。
这里的方法是使用 XML 表,当使用特制的 URL 和我们想要的结果的路径进行查询时,该表将返回您想要的照片集。下面,我们将使用我的 API 密钥进行查询(以节省您获得自己的密钥,尽管这是一个好主意),并从 在雅虎工作的开发者传播者(我必须选择一个人,第一个想到的是他的 Flickr)。
(在 YQL 控制台中尝试此查询)
从该查询返回的 XML 结构(以及通常的 YQL 内容)看起来像下面的代码片段(除非您返回 JSON,它将包含相同的信息,只是不是 XML 格式)。
然后你就可以随心所欲地处理这个结果。由于这个问题更多的是关于从 Flickr 查询特定信息而不是如何使用 YQL,因此我将省略在您选择的编程语言中使用它以及处理结果的详细信息。如果您不了解此类事情,请开始一个新问题。
之前我说过还有另一种方法。
2. 制作自定义 flickr.photosets.getList 表
构建用于查询的定制表的详细信息会超出此处合理答案的范围:要阅读基础知识和详细信息,请转到关于此主题的 YQL 文档位于 http://developer.yahoo .com/yql/guide/yql-creating-opentables-chapter.html
该表本身非常基本,除了上面的原始查询之外不会做任何其他事情;好处只是隐藏了细节。因此,我将首先展示该表,然后展示如何使用它。
该表是一个 XML 文档,描述如何与 Flickr 的
flickr.photosets.getList
方法进行交互。要使用此自定义表,您需要将其在线托管到 YQL 可以看到的位置。我已将其上传到 Yahoo! 的存储,这就是为什么 URL (
store://...
) 可能看起来有点奇怪。现在进入您一直在等待的部分:对您有用的东西!
如何使用我们的自定义表
(在 YQL 控制台中尝试此查询)
结论
上面的内容(只是最后一个查询,因为我已经为您制作了表格)是获取 Flickr 用户照片集列表所需的全部内容。简单地说:
最后,要获取属于一组的照片,已经有一个名为
flickr.photosets.photos
的内置表,因此您甚至不需要使用
自定义表格: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 thexml
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).
(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).
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
methodTo 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
(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:
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 touse
a custom table: