如何使用 YQL 获取用户的所有 flickr 照片集?

发布于 2024-09-11 11:53:59 字数 62 浏览 5 评论 0 原文

我需要做的就是找到 user_id 的所有照片集,然后如果使用 YQL 单击照片集,则获取该照片集中的所有照片

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清引 2024-09-18 11:53:59

目前还没有内置表可用于针对 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)。

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"

(在 YQL 控制台中尝试此查询)

从该查询返回的 XML 结构(以及通常的 YQL 内容)看起来像下面的代码片段(除非您返回 JSON,它将包含相同的信息,只是不是 XML 格式)。

    <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>

然后你就可以随心所欲地处理这个结果。由于这个问题更多的是关于从 Flickr 查询特定信息而不是如何使用 YQL,因此我将省略在您选择的编程语言中使用它以及处理结果的详细信息。如果您不了解此类事情,请开始一个新问题。

之前我说过还有另一种方法。

2. 制作自定义 flickr.photosets.getList 表

构建用于查询的定制表的详细信息会超出此处合理答案的范围:要阅读基础知识和详细信息,请转到关于此主题的 YQL 文档位于 http://developer.yahoo .com/yql/guide/yql-creating-opentables-chapter.html

该表本身非常基本,除了上面的原始查询之外不会做任何其他事情;好处只是隐藏了细节。因此,我将首先展示该表,然后展示如何使用它。

该表是一个 XML 文档,描述如何与 Flickr 的 flickr.photosets.getList 方法进行交互。

<?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>

要使用此自定义表,您需要将其在线托管到 YQL 可以看到的位置。我已将其上传到 Yahoo! 的存储,这就是为什么 URL (store://...) 可能看起来有点奇怪。

现在进入您一直在等待的部分:对您有用的东西!

如何使用我们的自定义表

use "store://github.com/flickr/photosets/getList" as photosets;
select * from photosets where user_id="11414938@N00"

(在 YQL 控制台中尝试此查询)

结论

上面的内容(只是最后一个查询,因为我已经为您制作了表格)是获取 Flickr 用户照片集列表所需的全部内容。简单地说:

use "store://github.com/flickr/photosets/getList" as photosets;
select * from photosets where user_id="11414938@N00"

最后,要获取属于一组的照片,已经有一个名为 flickr.photosets.photos 的内置表,因此您甚至不需要使用自定义表格:

select * from flickr.photosets.photos where photoset_id='72157624272957243'

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'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文