如何使用javascript加载google drive api?

时间:2017-11-17 17:47:17

标签: google-drive-api gapi

我像这样加载gapi:

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

期望加载后gapi.client.drive可用,但它会解析为null。我缺少什么想法?

1 个答案:

答案 0 :(得分:1)

好的,我弄明白了 - 加载库后我失去了gapi.client.init步骤:

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