Reputation: 730
I'm getting a 404 file not found error when using the google drive v3 API. The file-Id I'm getting from google picker so I know the id is correct. The offending code is as following (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);
});
}
Funnily enough it doesn't happen with all files only private files. So I assume the file not found error is just a generic response back from google indicating I wasn't allowed to access the file.
Oddly enough doing a files.get works fine:
gapi.client.drive.files.get({
fileId: _this.selectedFileId,
supportsTeamDrives: true
}).then(function (response) {
console.log('worked');
}, function (error) {
console.log('failed');
});
Upvotes: 1
Views: 1812
Reputation: 64700
I saw this same error when I used the https://www.googleapis.com/auth/drive.file permission: to get export to work you need to have at least the https://www.googleapis.com/auth/drive.readonly permission granted to the OAuth token you are using.
Upvotes: 5