forked from ShivamJoker/Ylight-Music
-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtubeAuth.html
75 lines (74 loc) · 2.36 KB
/
youtubeAuth.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for youtube.videos.list
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
function authenticate() {
return gapi.auth2
.getAuthInstance()
.signIn({ scope: "https://www.googleapis.com/auth/youtube.readonly" })
.then(
function() {
console.log("Sign-in successful");
},
function(err) {
console.error("Error signing in", err);
}
);
}
function loadClient() {
gapi.client.setApiKey("AIzaSyBvt3FKkCTs05Lo0RMfYS6DCBHJELJn7_Q");
return gapi.client
.load("https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest")
.then(
function() {
console.log("GAPI client loaded for API");
},
function(err) {
console.error("Error loading GAPI client for API", err);
}
);
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.youtube.videos
.list({
part: "snippet",
maxResults: 20,
myRating: "like",
videoCategoryId: "10"
})
.then(
function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) {
console.error("Execute error", err);
}
);
}
gapi.load("client:auth2", function() {
gapi.auth2.init({
client_id:
"367279527036-u1jsag8ol4djckc0r9s3lu14jf096eei.apps.googleusercontent.com"
});
});
</script>
<button onclick="authenticate().then(loadClient)">
authorize and load
</button>
<button onclick="execute()">execute</button>
</body>
</html>