0

この件については多くの質問がありましたが、すべての回答は古いgdata URLから始まります。これはもう動作しません。 https://www.youtube.com/feed/subscriptions

は明らかにこれはtampermonkeyスクリプトです:
私は、このページ(追加)ボタンをクリックすると、すべての動画のコメントを取得したいと思います。
私の仕上げは、私はコンテンツからちょっとしたピークを得ているので、私はyoutubeリンクのためのwhanaのクリックを断ることができます。
私はコメントの返信機能を計画するかもしれませんが、これは単なる将来の計画です。
私が今持っている:JqueryとYoutube API V3を使用してYoutubeのコメントを取得するにはどうすればよいですか?

// ==UserScript== 
// @name   hovercards for youtube 
// @namespace http://tampermonkey.net/ 
// @version  0.1 
// @description try to take over the world! 
// @author  You 
// @match  https://www.youtube.com/* 
// @grant  none 
// @require  https://code.jquery.com/jquery-latest.min.js 

// ==/UserScript== 
/* jshint -W097 */ 
    //'use strict'; 

jQuery(document).ready(function() { 
$("a.yt-uix-tile-link,.yt-ui-ellipsis-2k").on("mouseover",function() { 
     //Replace video block start  
$(function() { 
    $('a.yt-uix-tile-link,.yt-ui-ellipsis-2k').each(function() { 
     var yt_url = this.href, 
      yt_id = yt_url.split('?v=')[1], 
      yt_title = $(this).text(); 
     $(this).replaceWith('<div class="youtube-box" style="background-image:url(https://img.youtube.com/vi/' + yt_id + '/0.jpg);"><span class="youtube-title">' + yt_title + '</span><span class="youtube-bar"><span class="yt-bar-left"></span><span class="yt-bar-right"></span></span> </div>'); 
     $("div.youtube-box").on("mouseover",function() { 
      $(this).replaceWith('<iframe width="560" height="315" frameborder="0" allowfullscreen class="youtube-frame" src="https://www.youtube.com/embed/' + yt_id + '?autoplay=1"></iframe>'); 
     }); 
    }); 
}); 
    //Replace video block end 
}); 

}); 

そして、私はこの時点では、そのコードisent作業をsepareteしたいと思いますので、私はもちろんの作業形式でこれを追加したい:

jQuery(document).ready(function() { 
jQuery("'a.yt-uix-tile-link,.yt-ui-ellipsis-2k").append("<input type='button' value='Give me my comments' class='button'>"); 
jQuery(".button").on("click",function() { 
jQuery.getJSON('https://www.googleapis.com/youtube/v3/comments?id=yVqreR8VXwQ&key=YOURAPIKEY&part=snippet',function(data){ 
//Replace the YOURAPI key section for your key 
if (typeof(data.items[0]) != "undefined") { 
    console.log('video exists ' + data.items[0].snippet.comment); 
    $(".result").append(data.items[0].snippet.comment); 
    } else { 
    console.log('video not exists'); 
    jQuery("result").append("Nope, we don't get any data"); 
} 
}); 
}); 
}); 

IこのURLは私のAPIキーをbroweserに見えた:
'https://www.googleapis.com/youtube/v3/comments?id=yVqreR8VXwQ&key=YOURAPIKEY&part=snippet'
私はこの結果を得る:

{ 
"kind": "youtube#commentListResponse", 
"etag": "\"kiOs9cZLH2FUp6r6KJ8eyq_LIOk/pGLBhpjR05yQoJV31WoAx2PEFVw\"", 
"items": [] 
} 

そして私はなぜ、なぜ私はどんなアイテムを得るdosen't理解していないのですか?
URLはうまく見えます。

答えて

1
 GET https://www.googleapis.com/youtube/v3/commentThreads?key=AIzaSyDDBk8tAkod1VRRNyFZF09fgQyMpnSe5HI&textFormat=plainText&part=snippet&videoId=kffacxfA7G4&maxResults=50

あなたはそれが私のために正常に動作しています、これを試すことができます。

+0

私はこれを巧みにして答えました: http://jsfiddle.net/bTLX8/15/ 唯一の問題は、1つのビデオだけでなく、もっと多くのビデオを持っていることです。 idストリングを実際のビデオIDに変換します。 どのようにこのpossoble? – user3545446

関連する問題