【问题标题】:How to detect the last entry, youtube gdata search api如何检测最后一个条目,youtube gdata search api
【发布时间】:2013-02-06 09:15:46
【问题描述】:

我为我的 iphone 应用程序使用了 youtube 搜索 api。我一次请求 25 条记录。

     https://gdata.youtube.com/feeds/api/videos?q=%s&start-index=%d&max-results=25&v=2 

我想检测,查询捕获的最终记录。

例如:- 认为“阿凡达电影”有 135 个结果,在第 135 条记录处我想指示不再有搜索结果。

我正在使用视频列表末尾的“更多”按钮。我想禁用更多按钮。

【问题讨论】:

    标签: iphone search youtube-api


    【解决方案1】:

    对于第 2 版 API,您可以通过 2 种方式检测最后一项:

    1.

    <openSearch:totalResults>108</openSearch:totalResults>
    

    如果你知道总数,你就可以计算最后一项。

    2。是否返回下一个链接标签,如&lt;link rel='next' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos?q=rawangboy&amp;amp;start-index=108&amp;amp;max-results=1&amp;amp;restriction=US&amp;amp;safeSearch=strict&amp;amp;v=2'/&gt;

    但是,您需要 safeSearch 参数以确保 &lt;openSearch:totalResults&gt; 等同于您的最后一个项目索引,例如 https://gdata.youtube.com/feeds/api/videos?q=rawangboy&amp;start-index=108&amp;max-results=1&amp;v=2&amp;prettyprint=True&amp;safeSearch=none

    或者更好的是,您可以按国家/地区/IP 提供限制,例如https://gdata.youtube.com/feeds/api/videos?q=rawangboy&start-index=108&max-results=1&v=2&prettyprint=True&safeSearch=strict&restriction=US

    如果你没有放 safeSearch,&lt;openSearch:totalResults&gt; 可能不正确,如这个截图所示(start-index 107 不可用,即使总数为 108)

    搜索查询不允许超过 1000 个结果。 这里 https://developers.google.com/youtube/2.0/reference#Limits_on_Retrieving_Results‌​.

    【讨论】:

    • 非常感谢您的回答,我尝试使用“steve”关键字。 XML 显示,1000000 但我们不能请求超过 999 条记录。你能帮助这种情况吗?为什么我们不能超过 999 ,我应该为获得更多记录付费。
    【解决方案2】:

    如果您使用 Data API v3,当您“搜索”时,您将获得“pageInfo.totalResults”。 你可以检查一下,你可以检查 'nextPageToken' 是否为空,所以这是最后一页。

    'https://developers.google.com/youtube/v3/docs/search/list#response'

    【讨论】:

      猜你喜欢
      • 2011-11-12
      • 2015-03-24
      • 2013-08-10
      • 2012-05-27
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 2013-03-19
      • 1970-01-01
      相关资源
      最近更新 更多