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

Commit f335a49

Browse files
Add files via upload
1 parent 653be5b commit f335a49

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

docready.js

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

index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<html>
2+
<head>
3+
<title>YouTube Channel Activities</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/SimpleYTCSE/script.js"></script>
6+
<script src="auth.js"></script>
7+
<script async src="https://rawgit.com/DevelopersWork/CodingWithAPIs/YTChannelActivities/script.js"></script>
8+
<script async src="https://rawgit.com/DevelopersWork/CodingWithAPIs/YTChannelActivities/docready.js"></script>
9+
</head>
10+
<body>
11+
<section id="display">
12+
Channel Keyword/Title/Id: <input id="searchBar"><br>
13+
Max Results to be Displayed: <input id="maxResults" value="5"><br>
14+
<button onClick="buttonClickedSearchChannelActivities()">submit</button>
15+
</section>
16+
</body>
17+
</html>

script.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
var channelActivitiesUpload=[],channelActivitiesVideoView=[],channelActivitiesSubscription=[],
2+
reference=[];
3+
4+
function buttonClickedSearchChannelActivities(){
5+
var keyword = document.getElementById('searchBar').value;
6+
var max = document.getElementById('maxResults').value;
7+
document.getElementById('display').innerHTML='Channel Keyword/Title/Id: <input id="searchBar"><br>\
8+
Max Results to be Displayed: <input id="maxResults" value="5"><br>\
9+
<button onClick="buttonClickedSearchChannelActivities()">submit</button>';
10+
searchChannelsCode(keyword);
11+
var YTCI = [];
12+
var i=0;
13+
channelActivitiesCode(channelId[i],max);
14+
YTCI = channelId;
15+
$('#display').append('<div id="'+channelId[i]+'"align="center"><img src="'+channelThumbnail[i]+'"/>\
16+
<a href="https://youtube.com/channel/'+channelId[i]+'" target="_blank"><H3>'+channelTitle[i]+'</H3></a>\
17+
</div>');
18+
for(j=0;j<reference.length;j++){
19+
channelActivitiesDisplay(YTCI[i],reference[j],j);
20+
}
21+
};
22+
23+
function channelActivitiesCode(YouTubeChannelId,max=5){
24+
var API_KEY = API();
25+
$.ajax({
26+
url:'https://www.googleapis.com/youtube/v3/activities',
27+
data:{
28+
key:API_KEY,
29+
part:'contentDetails',
30+
maxResults:max,
31+
channelId:YouTubeChannelId
32+
},
33+
async:false,
34+
success:function(data){
35+
temp = data.items;
36+
for(var i=0;i<temp.length;i++){
37+
temp[i]=temp[i].contentDetails;
38+
if(temp[i].upload){
39+
channelActivitiesUpload[i] = temp[i].upload.videoId;
40+
reference[i]='upload';
41+
}else if(temp[i].bulletin){
42+
channelActivitiesVideoView[i] = temp[i].bulletin.resourceId.videoId;
43+
reference[i]='videoView';
44+
}else if(temp[i].subscription){
45+
channelActivitiesSubscription[i] = temp[i].subscription.resourceId.channelId;
46+
reference[i]='subscription';
47+
}
48+
}
49+
}
50+
});
51+
};
52+
53+
function channelActivitiesDisplay(YouTubeChannelId,i='.',j=0,){
54+
if(i=='upload'){
55+
$('#'+YouTubeChannelId).append('<div id="'+channelActivitiesUpload[j]+'"><h2>VIDEO UPLOAD:</h2>\
56+
<iframe src="https://youtube.com/embed/'+channelActivitiesUpload[j]+'"></iframe>\
57+
</div><br>');
58+
}else if(i=='videoView'){
59+
$('#'+YouTubeChannelId).append('<div id="'+channelActivitiesVideoView[j]+'"><h2>VIDEO VIEW:</h2>\
60+
<iframe src="https://youtube.com/embed/'+channelActivitiesVideoView[j]+'"></iframe>\
61+
</div><br>');
62+
}else if(i=='subscription'){
63+
searchChannelsCode(channelActivitiesSubscription[j]);
64+
$('#'+YouTubeChannelId).append('<div id="'+channelActivitiesSubscription[j]+'"><h2>SUBSCRIPTION:</h2>\
65+
<div id="'+channelId[0]+'"align="center"><img src="'+channelThumbnail[0]+'"/>\
66+
<a href="https://youtube.com/channel/'+channelId[0]+'" target="_blank"><H3>'+channelTitle[0]+'</H3></a>\
67+
</div>\
68+
</div><br>');
69+
}
70+
else $('#'+YouTubeChannelId).append('.<br>');
71+
72+
}
73+

0 commit comments

Comments
 (0)