使用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');
});
当我使用https://www.googleapis.com/auth/drive.file权限时,我看到同样的错误:要导出到工作,您需要至少授予您正在使用的OAuth令牌的https://www.googleapis.com/auth/drive.readonly权限。