2

my code is this

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

i have 100000 video ids in the video_arr array. Clearly the above code will take a lot of time as I am sending requests on by one. Is there any way of fetching the response of comments in a single request or in batches. Thx in advance

4

1 回答 1

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>
于 2013-05-01T05:29:55.673 回答