Youtube API :如何检索超过1000条评论


Youtube API : How to retrieve more than 1000 comments?

我正在尝试制作一种工具,可以从视频中获取所有评论并检索所有发表评论的用户,以使赠品更容易

现在我正在使用 Youtube API

gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments?v=2&alt=json&start-index=1

我只是做了一个简单的循环,每次递增起始索引(1、22、44、66 等)以获得所有注释

问题是我现在对视频有超过 1000 条评论,所以这不起作用,例如:gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments?v=2&alt=json&start-index=1100

http://pastebin.com/ypLrFmTG

有没有办法让所有在 Youtube 视频上发表评论的用户?我为此工作了几个小时以了解 Youtube api 的工作原理,但这个问题使整个事情毫无用处

我应该使用 curl 还是其他方式在这些页面上获取内容:youtube.com/all_comments?threaded=1&v=VIDEO_ID&page=x

嗯,有几种方法。首先是你发布的沙德拉西尔链接。如果你查看他们的javascript,然后将其分解(或者只是在fiddler中观察流量),它会访问其网站上的评论.php页面并传递页码。网址格式为:http://www.sandracires.com/en/client/youtube/comments.php?v=videoID&page=1。但是,我不确定这样做的合法性,所以我不推荐它。

我在Youtube上使用了Fiddler,这就是我想出的。

http://youtube.com/watch_ajax?action_get_comments=1&v=videoID&p=4&commentthreshold=-5&commenttype=everything&last_comment_id=teKFzQ8cbHNiI0ouIIqSS7lHeH2TZ8eWGlW-0D0Fx5U&page_size=500&source=w

  • v = 视频ID
  • p = 页码
  • 注释阈值 = ???
  • 注释类型 = 注释类型(一切都是我所知道的唯一枚举值)
  • last_comment_id = 在要加载的注释之前进行注释
  • page_size = 要返回的评论数
  • 源 = ???(也许 w 代表网络)

您也许能够删除源参数和其他参数。

我不完全确定这些是否都是正确的。我认为 p 是页码,这将允许您在没有 last_comment_id 参数的情况下拉取评论(它像这样对我有用)。我还通过解析生成的 XML 并找到?lc=LASTCOMMENTIDHERE,使 last_comment_id 参数正常工作(其中 p 保持不变)。

似乎一次最多有 500 个。是的,我试过501。正如我所指出的,数据以XML形式返回。每条评论如下所示:

<div class="content clearfix">
  <p class="metadata">
    <span class="author ">
      <a href="/user/mindmonkey00" class="g-hovercard yt-uix-sessionlink yt-user-name " data-sessionlink="ei=-LFcUvCPNsn-sAf7jIGgAg" dir="ltr" data-ytid="UCAufDxGRQh_LlF5tD6StNtw" data-name="">mindmonkey00</a>
    </span>
      <span class="time" dir="ltr">
        <a dir="ltr" href="http://www.youtube.com/comment?lc=teKFzQ8cbHNkP8a89kiIEtWqiTRiAkKtSnvEHB_hXG4">
          3 weeks ago
        </a>
      </span>
  </p>

  <div class="comment-text" dir="ltr">
    <p>You didn&#39;t answer my question?</p>
  </div>
  <div class="comment-actions">
    <button onclick=";return false;" type="button" class="start comment-action create-channel-lightbox yt-uix-button yt-uix-button-link yt-uix-button-size-default" data-upsell="comment" role="button"><span class="yt-uix-button-content">Reply </span></button>
    <span class="separator">&middot;</span>

    <span ><button title="Vote Up" onclick=";return false;" type="button" class="start comment-action-vote-up comment-action yt-uix-button yt-uix-button-link yt-uix-button-size-default yt-uix-button-has-icon yt-uix-tooltip yt-uix-button-empty" data-tooltip-show-delay="300" data-action="vote-up" role="button"><span class="yt-uix-button-icon-wrapper"><img class="yt-uix-button-icon yt-uix-button-icon-watch-comment-vote-up" src="//s.ytimg.com/yts/img/pixel-vfl3z5WfW.gif" alt="Vote Up" title=""></span></button></span><span ><button title="Vote Down" onclick=";return false;" type="button" class="end comment-action-vote-down comment-action yt-uix-button yt-uix-button-link yt-uix-button-size-default yt-uix-button-has-icon yt-uix-tooltip yt-uix-button-empty" data-tooltip-show-delay="300" data-action="vote-down" role="button"><span class="yt-uix-button-icon-wrapper"><img class="yt-uix-button-icon yt-uix-button-icon-watch-comment-vote-down" src="//s.ytimg.com/yts/img/pixel-vfl3z5WfW.gif" alt="Vote Down" title=""></span></button></span>
  </div>
</div>

请记住,通过尝试规避 Youtube 的 API 规则,您可能不得不每隔一段时间重做此过程。他们可能会更改网址。