I am developing using Google Drive API via JavaScript. I tried the example code and found that it works fine. However, the same code did not work with the chrome-extension. I guess it's a problem with the Client ID value, but I do not think it's strange, Why does not it work with Chrome extensions?
// Client ID and API key from the Developer Console
var CLIENT_ID = '467319036759-udrp5jb3257p1kd11n5016rdid4qm8kd.apps.googleusercontent.com';
// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"];
// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = 'https://www.googleapis.com/auth/drive';
var authorizeButton = document.getElementById('authorize-button');
var signoutButton = document.getElementById('signout-button');
/**
* On load, called to load the auth2 library and API client library.
*/
function handleClientLoad() {
gapi.load('client:auth2', initClient);
console.log("load ok");
}
/**
* Initializes the API client library and sets up sign-in state
* listeners.
*/
function initClient() {
gapi.client.init({
discoveryDocs: DISCOVERY_DOCS,
clientId: CLIENT_ID,
scope: SCOPES
}).then(function () {
// Listen for sign-in state changes.
console.log("client ok");
gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
// Handle the initial sign-in state.
updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
authorizeButton.onclick = handleAuthClick;
signoutButton.onclick = handleSignoutClick;
}, function(error) {
console.log(error);
});
console.log("client");
}
Console log does not display "client ok"
The address of the extension I have registered is https://chrome.google.com/webstore/detail/study/minmfnjifbdpcphgildjgfpnbiejajml