Andrey
Andrey

Reputation: 21285

How do I load google drive api with javascript?

I load gapi like this:

gapi.load('client:auth2', () => {
      var auth2 = gapi.auth2.init({
          client_id: `${MYKEY}.apps.googleusercontent.com`,
          scope: 'profile https://www.googleapis.com/auth/drive.appfolder'
      });
      console.log(gapi.client.drive)
}

expecting that gapi.client.drive will be available after it loads, but it resolves to null. Any ideas what I'm missing?

Upvotes: 0

Views: 541

Answers (1)

Andrey
Andrey

Reputation: 21285

Ok, I figured it out - I was missing gapi.client.init step after loading the library:

gapi.client.init({
        'apiKey': 'API_KEY',
        'discoveryDocs': ['https://www.googleapis.com/discovery/v1/apis/drive/v3/rest'],
        'clientId': 'CLIENT_ID.apps.googleusercontent.com',
        'scope': 'https://www.googleapis.com/auth/drive.appfolder',
      }).then(SOME_CALLBACK);

Upvotes: 1

Related Questions