1

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");
  }

enter image description here

Console log does not display "client ok"

The address of the extension I have registered is https://chrome.google.com/webstore/detail/study/minmfnjifbdpcphgildjgfpnbiejajml

Makyen
  • 31,849
  • 12
  • 86
  • 121
megu
  • 11
  • 1
  • 3
  • What _does_ the console display? Are you looking in the right console (the one invoked by Inspect Popup in your case)? – Xan Aug 24 '17 at 10:33
  • console log displays "load ok" and "client". I hope for 'client ok'. Strangely, the 'gapi.client.init' method leaves no log. – megu Aug 24 '17 at 11:09
  • Please [edit] the question to be on-topic: include a [mcve] that *duplicates the problem*. For Chrome extensions or Firefox WebExtensions you almost always need to include your *manifest.json* and some of the background, content, and/or popup scripts/HTML, and often webpage HTML/scripts. Questions seeking debugging help ("why isn't my code working the way I want?") must include: (1) the desired behavior, (2) a specific problem or error and (3) the shortest code necessary to reproduce it *in the question itself*. Please also see: [What topics can I ask about here?](/help/on-topic), and [ask]. – Makyen Aug 24 '17 at 17:52
  • Make sure the client ID and API key you're using is specified for chrome app and chrome extension from your Google Dev console. You can also refer to this [SO post](https://stackoverflow.com/questions/10330992/authorization-of-google-drive-using-javascript/10331393#10331393) for implementation specific details. – ReyAnthonyRenacia Aug 25 '17 at 11:27
  • Hi megu, did it worked for you? – Kanak Sony Mar 09 '18 at 18:54

1 Answers1

0

It looks like Chrome extensions are not supported: https://github.com/google/google-api-javascript-client/issues/258

Max G.
  • 266
  • 1
  • 6