グーグルクライアントライブラリを用いてYouTubeDataAPIの利用を試みたところ、
Uncaught message cb=gapi.loaded_0:367 Uncaught
:
"Missing required parameter 'client_id'"
stack
:
"gapi.auth2.ExternallyVisibleError: Missing required parameter 'client_id'↵
とコンソールに表示されます。
調べてみたのですが、原因がわかりません。
ご教授お願い致します。
html
1sample.html 2jQueryのcdnを最新版にしています。 3 4<!doctype html> 5<html> 6 <head> 7 <meta charset="UTF-8"> 8 <title>Search</title> 9 </head> 10 <body> 11 <div id="buttons"> 12 <label> <input id="query" value='cats' type="text"/><button id="search-button" disabled onclick="search()">Search</button></label> 13 </div> 14 <div id="search-container"> 15 </div> 16 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 17 <script src="auth.js"></script> 18 <script src="search.js"></script> 19 <script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script> 20 </body> 21</html>
javascript
1var OAUTH2_CLIENT_ID = 'google cloud consoleで作成したクライアントID'; 2var OAUTH2_SCOPES = [ 3 'https://www.googleapis.com/auth/youtube' 4]; 5 6googleApiClientReady = function() { 7 gapi.auth2.init(function() { 8 window.setTimeout(checkAuth, 1); 9 }); 10} 11 12function checkAuth() { 13 gapi.auth2.authorize({ 14 client_id: OAUTH2_CLIENT_ID, 15 scope: OAUTH2_SCOPES, 16 immediate: true 17 }, handleAuthResult); 18} 19 20function handleAuthResult(authResult) { 21 if (authResult && !authResult.error) { 22 $('.pre-auth').hide(); 23 $('.post-auth').show(); 24 loadAPIClientInterfaces(); 25 } else { 26 $('#login-link').click(function() { 27 gapi.auth2.authorize({ 28 client_id: OAUTH2_CLIENT_ID, 29 scope: OAUTH2_SCOPES, 30 immediate: false 31 }, handleAuthResult); 32 }); 33 } 34} 35 36function loadAPIClientInterfaces() { 37 gapi.client.load('youtube', 'v3', function() { 38 handleAPILoaded(); 39 }); 40}
javascript
1search.js 2 3// After the API loads, call a function to enable the search box. 4function handleAPILoaded() { 5 $('#search-button').attr('disabled', false); 6 } 7 8 // Search for a specified string. 9 function search() { 10 var q = $('#query').val(); 11 var request = gapi.client.youtube.search.list({ 12 q: q, 13 part: 'snippet' 14 }); 15 16 request.execute(function(response) { 17 var str = JSON.stringify(response.result); 18 $('#search-container').html('<pre>' + str + '</pre>'); 19 }); 20 }
あなたの回答
tips
プレビュー