質問編集履歴

4

情報更新

2019/05/29 08:51

投稿

hirahiro
hirahiro

スコア24

test CHANGED
@@ -1 +1 @@
1
- YouTube Data API(v3) がエラーで使用できない
1
+ YouTube Data API(v3) が使用できない
test CHANGED
@@ -30,21 +30,15 @@
30
30
 
31
31
  http://localhost:8080/search.html
32
32
 
33
- にて実行したところ、実行することができず、consoleで
33
+ にて実行したところ、実行することができません。
34
34
 
35
35
 
36
-
37
- ![イメージ説明](e21a38ca1f8c612908e906cd31a4365e.gif)
38
-
39
-
40
-
41
- のようなエラーがでました。
42
36
 
43
37
  ### 該当のソースコード
44
38
 
45
39
 
46
40
 
47
- サンプルで変更した箇所は auth.jsのみです
41
+ 追記した箇所は auth.jsです
48
42
 
49
43
 
50
44
 
@@ -70,16 +64,112 @@
70
64
 
71
65
 
72
66
 
67
+ // Upon loading, the Google APIs JS client automatically invokes this callback.
68
+
69
+ googleApiClientReady = function() {
70
+
71
+ gapi.auth.init(function() {
72
+
73
+ window.setTimeout(checkAuth, 1);
74
+
75
+ });
76
+
77
+ }
78
+
79
+
80
+
81
+ // Attempt the immediate OAuth 2.0 client flow as soon as the page loads.
82
+
83
+ // If the currently logged-in Google Account has previously authorized
84
+
85
+ // the client specified as the OAUTH2_CLIENT_ID, then the authorization
86
+
87
+ // succeeds with no user intervention. Otherwise, it fails and the
88
+
89
+ // user interface that prompts for authorization needs to display.
90
+
91
+ function checkAuth() {
92
+
93
+ gapi.auth.authorize({
94
+
95
+ client_id: OAUTH2_CLIENT_ID,
96
+
97
+ scope: OAUTH2_SCOPES,
98
+
99
+ immediate: true
100
+
101
+ }, handleAuthResult);
102
+
103
+ }
104
+
105
+
106
+
107
+ // Handle the result of a gapi.auth.authorize() call.
108
+
109
+ function handleAuthResult(authResult) {
110
+
111
+ if (authResult && !authResult.error) {
112
+
113
+ // Authorization was successful. Hide authorization prompts and show
114
+
115
+ // content that should be visible after authorization succeeds.
116
+
117
+ $('.pre-auth').hide();
118
+
119
+ $('.post-auth').show();
120
+
121
+ loadAPIClientInterfaces();
122
+
123
+ } else {
124
+
125
+ // Make the #login-link clickable. Attempt a non-immediate OAuth 2.0
126
+
127
+ // client flow. The current function is called when that flow completes.
128
+
129
+ $('#login-link').click(function() {
130
+
131
+ gapi.auth.authorize({
132
+
133
+ client_id: OAUTH2_CLIENT_ID,
134
+
135
+ scope: OAUTH2_SCOPES,
136
+
137
+ immediate: false
138
+
139
+ }, handleAuthResult);
140
+
141
+ });
142
+
143
+ }
144
+
145
+ }
146
+
147
+
148
+
149
+ // Load the client interfaces for the YouTube Analytics and Data APIs, which
150
+
151
+ // are required to use the Google APIs JS client. More info is available at
152
+
153
+ // https://developers.google.com/api-client-library/javascript/dev/dev_jscript#loading-the-client-library-and-the-api
154
+
155
+ function loadAPIClientInterfaces() {
156
+
157
+ gapi.client.load('youtube', 'v3', function() {
158
+
159
+ handleAPILoaded();
160
+
161
+ });
162
+
163
+ }
164
+
165
+
166
+
73
167
  ```
74
168
 
75
169
 
76
170
 
77
- youtube data api,content security policy といった単語で検索しても有用な情報が得られずご教授いただければと思います。
171
+ 上記サンプルコードにconsole.log()を仕込んでいったところ
78
172
 
173
+ checkAuth()内の gapi.auth.authorize のコールバック handleAuthResult() が呼び出されていないようでした。
79
174
 
80
-
81
- ### ネットワ
175
+ 特にエラは起きていないです。
82
-
83
-
84
-
85
- ![イメージ説明](0d58b4a83dc08c34806d8cd022deb9a6.gif)

3

情報更新

2019/05/29 08:51

投稿

hirahiro
hirahiro

スコア24

test CHANGED
File without changes
test CHANGED
@@ -75,3 +75,11 @@
75
75
 
76
76
 
77
77
  youtube data api,content security policy といった単語で検索しても有用な情報が得られず、ご教授いただければと思います。
78
+
79
+
80
+
81
+ ### ネットワーク
82
+
83
+
84
+
85
+ ![イメージ説明](0d58b4a83dc08c34806d8cd022deb9a6.gif)

2

誤字

2019/05/29 07:49

投稿

hirahiro
hirahiro

スコア24

test CHANGED
File without changes
test CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
 
28
28
 
29
- ローカホスト
29
+ ローカホスト
30
30
 
31
31
  http://localhost:8080/search.html
32
32
 

1

誤字

2019/05/29 06:54

投稿

hirahiro
hirahiro

スコア24

test CHANGED
@@ -1 +1 @@
1
- YouTubu Data API(v3) がエラーで使用できない
1
+ YouTube Data API(v3) がエラーで使用できない
test CHANGED
File without changes