2013-10-14 59 views
2

我試圖做一個工具,可以採取從視頻的所有意見,並取回所有發佈的評論的用戶,使贈品更容易Youtube API:如何檢索超過1000條評論?

現在,我使用YouTube API與

gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments?v=2 & ALT = JSON &啓動指數= 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取得的作品,但這個問題使得無用整個事情

應該我寧願用捲曲或其他方式來獲得這些網頁上的內容: youtube.com/all_comments? threaded = 1 & v = VIDEO_ID & page = x

+0

在查詢參數中存在拼寫錯誤,「max-result」應該是「max-results」 - 無論如何,根據https://developers.google.com/youtube/2.0/reference?hl=zh_CN#Paging_through_Results它看起來好像有一個1000的硬限制。「對於任何給定的查詢,即使有不止一個,也不能檢索超過1,000個結果。」 – Exupery

+0

該網站如何獲得所有評論? http://www.sandracires.com/en/client/youtube/random.htm 我無法使用cUrl,Simple dom解析器或任何有關http://www.youtube.com/all_comments?v=上的註釋ID&page = 2 – user2880435

+0

**更新**:我找到了一種使用Zend_Dom_Query,Curl,getElementsByTagName等的方法。我花了一段時間才弄明白。它的工作原理,但需要2分鐘,通過20 000評論 – user2880435

回答

3

好吧,有幾種方法。首先是你發佈的sandracire鏈接。如果你查看他們的javascript,然後把它分開(或只是看着小提琴手的流量),它會訪問其網站上的comments.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 = VIDEOID
  • P =頁碼
  • commentthreshold = ???
  • commenttype =註釋類型(一切是唯一的枚舉值我所知道的)
  • 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規則,你可能會在一段時間每一次重做這個過程。他們可能會改變網址。

+0

我可能會看看這樣做,但現在我的解決方案工作正常,需要一段時間才能加載時,有很多評論,但它不是一個真正的問題,因爲它只是一個個人工具,不會被釋放或任何 這是我的代碼,這可能看起來非常糟糕:http://puu.sh/4QALb.png 它需要13秒來處理1200個評論(共3頁) – user2880435

+0

的puu.sh似乎有過期。此外,sandracire的方式,如果這只是個人使用,速度更快,並返回格式良好的JSON。 –

+0

@Millie Smith你能解釋一下你是如何使用Fiddler解決方案提出上面的鏈接的?謝謝! – Thoth