Skip to content
This repository was archived by the owner on Oct 27, 2021. It is now read-only.

Commit c957471

Browse files
Add files via upload
1 parent 86ca476 commit c957471

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

docready.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
$(document).ready(function(){
3+
4+
});

index.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<html>
2+
<head>
3+
<title>YouTube Display Comment Replies On A Video</title>
4+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
5+
<script src="https://rawgit.com/DevelopersWork/CodingWithAPIs/SimpleYTVSE-VideoEmbed/script.js"></script>
6+
<script src="https://rawgit.com/DevelopersWork/CodingWithAPIs/GET-YTCommentsOnAVideo/script.js"></script>
7+
<script src="https://rawgit.com/DevelopersWork/CodingWithAPIs/YTCount-Views_Comments_Likes_Dislikes_Favorites/script.js"></script>
8+
<script src="auth.js"></script>
9+
<script async src="https://rawgit.com/DevelopersWork/CodingWithAPIs/GET-YTCommentRepliesOnAVideo/script.js"></script>
10+
<script async src="https://rawgit.com/DevelopersWork/CodingWithAPIs/GET-YTCommentRepliesOnAVideo/docready.js"></script>
11+
</head>
12+
<body>
13+
<section id="display">
14+
Video Keyword/Title/Id: <input id="searchBar"><br>
15+
Max Results to be Displayed: <input id="maxResults" value="25"><br>
16+
<button onClick="buttonClickedSearchCommentRepliesByVideoId()">submit</button>
17+
</section>
18+
</body>
19+
</html>

script.js

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
var commentRepliedId = [],
2+
commentRepliedAuthorDisplayName=[],commentRepliedAuthorProfileImageUrl=[],
3+
commentRepliedAuthorChannelId=[],commentRepliedTextDisplay=[],
4+
commentRepliedLikeCount=[],
5+
commentRepliedPublishedAt=[],commentRepliedUpdatedAt=[];
6+
7+
function buttonClickedSearchCommentRepliesByVideoId(){
8+
var keyword = document.getElementById('searchBar').value;
9+
document.getElementById('display').innerHTML = 'Video Keyword/Title/Id: <input id="searchBar"><br>\
10+
Max Results to be Displayed: <input id="maxResults" value="25"><br>\
11+
<button onClick="buttonClickedSearchCommentsByVideoId()">submit</button>';
12+
searchVideosCode(keyword);
13+
var i = 0,j = 0;
14+
//for(i=0;i<videoId.length;i++){
15+
commentsOnAVideoCode(videoId[i]);
16+
videosCountCode(videoId[i]);
17+
displayVideosCount(i);
18+
for(j=0;j<commentedId.length;j++){
19+
if(commentedTotalReplyCount[j]>0){
20+
document.getElementById(videoTitle[i]).outerHTML = '<h1 id="'+videoTitle[i]+'">'+videoTitle[i]+'</h1>';
21+
commentRepliesOnAVideoCode(commentedId[j]);
22+
commentRepliesOnAVideoDisplay(videoId[i],commentedId[j],j);
23+
}
24+
}
25+
26+
//}
27+
};
28+
29+
function commentRepliesOnAVideoCode(YouTubeCommentId,max=10){
30+
var API_KEY = API();
31+
32+
$.ajax({
33+
url:'https://www.googleapis.com/youtube/v3/comments',
34+
data:{
35+
key:API_KEY,
36+
parentId:YouTubeCommentId,
37+
part:'snippet',
38+
maxResults:max
39+
},
40+
async:false,
41+
success:function(data){
42+
temp = data.items;
43+
44+
for(var i=0;i<temp.length;i++){
45+
46+
commentRepliedId[i] = temp[i].id;
47+
48+
commentRepliedAuthorDisplayName[i] = temp[i].snippet.authorDisplayName;
49+
commentRepliedAuthorProfileImageUrl[i] = temp[i].snippet.authorProfileImageUrl;
50+
commentRepliedAuthorChannelId[i] = temp[i].snippet.authorChannelId.value;
51+
commentRepliedTextDisplay[i] = temp[i].snippet.textDisplay;
52+
53+
commentRepliedLikeCount[i] = temp[i].snippet.likeCount;
54+
commentRepliedPublishedAt[i] = temp[i].snippet.publishedAt;
55+
commentRepliedUpdatedAt[i] = temp[i].snippet.updatedAt;
56+
}
57+
}
58+
});
59+
};
60+
61+
function commentRepliesOnAVideoDisplay(YouTubeVideoId,YouTubeCommentedId,i=0){
62+
$('#video'+YouTubeVideoId).append('\
63+
<div id="comment'+commentedId[i]+'" style="border:5px solid red">\
64+
<img src="'+commentedAuthorProfileImageUrl[i]+'">\
65+
<a href="https://youtube.com/channel/'+commentdAuthorChannelId[i]+'" target="_blank">\
66+
<h1 id="'+commentdAuthorChannelId+commentedId[i]+'">"'+commentedAuthorDisplayName[i]+'"</h1>\
67+
</a>\
68+
<h2 id="'+commentedId[i]+'">\
69+
Comment:'+commentedTextDisplay[i]+'<br>\
70+
Replies:'+commentedTotalReplyCount[i]+'<br>\
71+
Likes for Comment:'+commentedLikeCount[i]+'<br>\
72+
Commented At:'+commentedPublishedAt[i]+'<br>\
73+
Last Edited:'+commentedUpdatedAt[i]+'<br></h2>\
74+
<br><br></div>\
75+
');
76+
for(i=0;i<temp.length;i++){
77+
$('#comment'+YouTubeCommentedId).append('\
78+
<div id="reply'+commentRepliedId[i]+'">\
79+
<img src="'+commentRepliedAuthorProfileImageUrl[i]+'">\
80+
<a href="https://youtube.com/channel/'+commentRepliedAuthorChannelId[i]+'" target="_blank">\
81+
<h1 id="'+commentRepliedAuthorChannelId+commentRepliedId[i]+'">"'+commentRepliedAuthorDisplayName[i]+'"</h1>\
82+
</a>\
83+
<h2 id="'+commentedId[i]+'">\
84+
Reply:'+commentRepliedTextDisplay[i]+'<br>\
85+
Likes for Reply:'+commentRepliedLikeCount[i]+'<br>\
86+
Commented At:'+commentRepliedPublishedAt[i]+'<br>\
87+
Last Edited:'+commentRepliedUpdatedAt[i]+'<br></h2>\
88+
</div>\
89+
');
90+
}
91+
};
92+

0 commit comments

Comments
 (0)