导出Google云端硬盘时找不到文件

问题描述 投票:0回答:1

使用google drive v3 API时,我收到404文件未找到错误。我从谷歌选择器获取的文件ID,所以我知道ID是正确的。违规代码如下(javascript):

downloadFile: function () {
      var _this = this;
      gapi.client.init({
        apiKey: this.developerKey,
        clientId: this.clientId,
        discoveryDocs: ['https://www.googleapis.com/discovery/v1/apis/drive/v3/rest'],
        scope: 'https://www.googleapis.com/auth/drive'
      }).then(function () {
        // not working with private files
        gapi.client.setToken(_this.oauthToken);
        gapi.client.drive.files.export({
          'fileId': _this.selectedFileId,
          'mimeType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        }).then(function (response) {
            console.log('success!');
          });
        }, function (error) {
          console.log(error);
        });
      }, function (error) {
        console.log(error);
      });
    }

有趣的是,它不会发生在所有文件中只有私有文件。所以我假设找不到文件错误只是谷歌的一般回复,表明我不允许访问该文件。

奇怪的是,做一个files.get工作正常:

 gapi.client.drive.files.get({
         fileId: _this.selectedFileId,
       supportsTeamDrives: true
       }).then(function (response) {
         console.log('worked');
       }, function (error) {
           console.log('failed');
       });
javascript google-drive-sdk
1个回答
1
投票

当我使用https://www.googleapis.com/auth/drive.file权限时,我看到同样的错误:要导出到工作,您需要至少授予您正在使用的OAuth令牌的https://www.googleapis.com/auth/drive.readonly权限。

© www.soinside.com 2019 - 2024. All rights reserved.