-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathytmashup.html
151 lines (127 loc) · 5.41 KB
/
ytmashup.html
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<head>
<title> 長輩圖 Mashup </title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://apis.google.com/js/api.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-134268415-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-134268415-1');
</script>
<script>
/**
* Sample JavaScript code for youtube.channels.list
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
function loadClientAndSearch() {
gapi.client.setApiKey("AIzaSyCLNYLDYcIO7PtEPqLpbIzKYOmRB4lDObk");
return gapi.client.load("https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest")
.then(function() { console.log("GAPI client loaded for API"); searchList(); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
gapi.load("client", function() {
// gapi.auth2.init({client_id: "669658571519-k0kf7okgs8mllgknbhkiehrccvc5e8au.apps.googleusercontent.com"});
loadClientAndSearch();
});
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
gapi.client.youtube.channels.list({
'part': 'snippet, contentDetails,statistics',
'forUsername': 'GoogleDevelopers'
}).then(function(response){
console.log(response);
var channel = response.result.items[0];
$("#result").val('This channel\'s ID is ' + channel.id + '. ' +
'Its title is \'' + channel.snippet.title + ', ' + 'and it has ' + channel.statistics.viewCount + ' views');
});
}
function getChannel() {
gapi.client.youtube.channels.list({
'part': 'snippet, contentDetails,statistics',
'forUsername': 'GoogleDevelopers'
}).then(function(response){
console.log(response);
var channel = response.result.items[0];
$("#result").val('This channel\'s ID is ' + channel.id + '. ' +
'Its title is \'' + channel.snippet.title + ', ' + 'and it has ' + channel.statistics.viewCount + ' views');
});
}
function searchList() {
gapi.client.youtube.search.list({
q: "長輩圖",
part: "snippet",
maxResults: "5",
type: "video",
videoEmbeddable: "true",
order: "date"
}).then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
var items = response.result.items;
if (items) {
items.forEach(function(searchResult) {
var videoId = searchResult.id.videoId;
var snippet = searchResult.snippet;
var title = snippet.title;
var description = snippet.description;
var channelTitle = snippet.channelTitle;
var channelId = snippet.channelId;
var publishedAt = snippet.publishedAt;
var publishDate = new Date(publishedAt);
appendVideo("https://www.youtube.com/embed/" + videoId, title, description, channelTitle, channelId, publishDate);
});
}
},
function(err) { console.error("Execute error", err); });
}
function appendVideo(src, title, description, channelTitle, channelId, publishDate) {
$("#videoContainer").append(
'<div class="card" style="width: 560;">' +
'<iframe ' +
'id="videoEmbed"' +
'width="560" ' +
'src="' + src + '"' +
'height="315" ' +
'frameborder="0"' +
'allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" ' +
'allowfullscreen>' +
'</iframe>' +
'<div class="card-body">' +
'<table>' +
'<td>' +
'<tr>' +
'<h5 class="card-title">' + title + '</h5>' +
'</td>' +
'</tr>' +
'<tr>' +
'<td>' +
'<a href="https://www.youtube.com/channel/' + channelId + '" >' + channelTitle + '</a>' +
'<h6 class="card-text">Published on: ' + publishDate.toDateString() + '</h5>' +
'<hr class="my-4">' +
'<p class="card-text">' + description + '</p>' +
'</td>' +
'</tr>' +
// '<a href="#" class="btn btn-primary">Go somewhere</a>' +
'</table>' +
'</div>' +
'</div>'
);
}
// $(document).ready(function(){
// searchList();
// });
</script>
</head>
<!-- <button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>
<button onclick="init()">execute</button>
<button onclick="init().then(searchList)">init and search</button>
<button onclick="searchList()">search</button>
<input type="text" id="result"></input> -->
<div id="videoContainer">
</div>