在单个请求或批量中获取多个视频的YouTube视图评论

时间:2013-05-01 04:54:44

标签: ruby-on-rails youtube-api

我的代码就是这个

video_arr = ["o9_5dnC0iLA","h4yWRY2Yg3Q","jnia6bw3eeo","cAPpaM2Oszc"]
video_arr.ech do |video_id|
 xml = open("http://gdata.youtube.com/feeds/api/videos/#{video_id}/comments").read
  comments_hash = Nori.parse(xml)
  if !comments_hash['feed']['entry'].blank?
    comments_hash['feed']['entry'].each { |entry|
     puts entry['content']
    }
  end

end

我在video_arr数组中有100000个视频ID。很明显,上面的代码将花费大量时间,因为我发送一个请求。有没有办法在单个请求或批量中获取注释的响应。  Thx提前

1 个答案:

答案 0 :(得分:0)

尝试使用此正文发送api请求

<feed>
  <batch:operation type="query"/>
  <entry>
    <gd:comments>
      <gd:feedLink
        href='https://gdata.youtube.com/feeds/api/videos/VIDEO_ID_1/comments'/>
    </gd:comments>
  </entry>
  <entry>
    <gd:comments>
      <gd:feedLink
        href='https://gdata.youtube.com/feeds/api/videos/VIDEO_ID_2/comments'/>
    </gd:comments>
  </entry>

   ...

  <entry>
    <gd:comments>
      <gd:feedLink
        href='https://gdata.youtube.com/feeds/api/videos/VIDEO_ID_N/comments'/>
    </gd:comments>
  </entry>
</feed>