2013-05-01 48 views
2

我的代碼是這樣取的多個視頻YouTube評論在單個請求中或分批

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

回答

0

試圖發送與該主體

<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> 
API請求
相關問題