samedi 3 août 2019

Google window.gapi.client.init not resolving nor rejecting promise

I'm trying to set up an Ember project in a Chrome extension. The project works perfectly fine in the browser with my Web Application OAuth 2.0 client ID. However when I use my Chrome App OAuth 2.0 client ID and load my Ember app into Chrome, the window.gapi.client.init call never resolves nor rejects. Neither client.init... then... is logged nor error! is logged (see code). Any ideas why this call would hang in a Chrome extension but be ok in the browser?

My code:

window.gapi.load('client:auth2', () => this.initClient());

which calls:

  initClient() {
    console.log('initClient');
    window.gapi.client.init({
      apiKey: API_KEY,
      clientId: CLIENT_ID,
      discoveryDocs: DISCOVERY_DOCS,
      scope: SCOPES
    }).then(() => {
      console.log('client.init... then...')
      // Listen for sign-in state changes.
      window.gapi.auth2.getAuthInstance().isSignedIn.listen((isSignedIn) => this.updateSigninStatus(isSignedIn));

      // Handle the initial sign-in state.
      this.updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
      this.authorizeButton.onclick = this.handleAuthClick;
      this.signoutButton.onclick = this.handleSignoutClick;
    }, (error) => {
      // debugger
      console.log('error!');
      console.log(error);
      this.appendPre(JSON.stringify(error, null, 2));
    });

My manifest.json:

  "description": "Build an Ember Chrome Extension!",
  "permissions": ["identity", "storage", "activeTab", "geolocation"],
  "oauth2": {
    "client_id": "my-chrome-app-client-id.apps.googleusercontent.com",
    "scopes": [
      "https://www.googleapis.com/auth/calendar.readonly",
      "https://www.googleapis.com/auth/calendar.events.readonly"
    ]
  }
  ...

Only initClient is logged to the dev console, nothing else. I tried looking at this but it didn't help.




Aucun commentaire:

Enregistrer un commentaire