-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
52 lines (49 loc) · 1.62 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function getUsersPlaylist(channel) {
var data = {
part : 'contentDetails',
forUsername : channel,
key : 'AIzaSyBoLArgB7n25mqBcIGipwDcBkb6Yi6gQzU',
};
superagent
.get('https://www.googleapis.com/youtube/v3/channels')
.query(data)
.set('Accept', 'application/json')
.end(function(err, res) {
if (err || !res.ok) {
alert('Oh no! error');
} else {
res.body.items.forEach(function(item, i) {
var pid = item.contentDetails.relatedPlaylists.uploads
getUsersVideos(pid);
});
}
});
}
function getUsersVideos(pid) {
var data = {
part : 'snippet',
maxResults : 10,
playlistId : pid,
key : 'AIzaSyBoLArgB7n25mqBcIGipwDcBkb6Yi6gQzU',
order : 'date'
};
superagent
.get('https://www.googleapis.com/youtube/v3/playlistItems')
.query(data)
.set('Accept', 'application/json')
.end(function(err, res) {
if (err || !res.ok) {
alert('Oh no! error');
} else {
res.body.items.forEach(function(video, i) {
var html = '<div class="video"> \
<a href="//youtube.com/watch?v=' + video.snippet.resourceId.videoId + '" class="title">\
<img src="//img.youtube.com/vi/' + video.snippet.resourceId.videoId + '/maxresdefault.jpg">' +
video.snippet.title + '</a> \
</div>';
document.querySelector('.videos').innerHTML += html;
});
}
});
}
getUsersPlaylist('testedcom');