2021年3月9日星期二

Upload a excel file with google drive api

I'm having a problem with the google drive API.

I'm trying to upload an excel file with this API, but it's not working. Even copying the google API documentation doesn't work.

Here is a sample of my code:

@Get('teste')  async teste(){      const keys = require(path.resolve('src', 'files', 'api', 'keys'))      const client = new google.auth.JWT(          keys.client_email,          null,          keys.private_key,          ['https://www.googleapis.com/auth/drive.metadata.readonly']      )        client.authorize((err, tokens) =>{          if(err){              console.log(err)              return;          } else{              this.gdrun(client)          }      })    }    gdrun(client){      const drive = google.drive({version: 'v3', auth: client});        var fileMetadata = {          name: 'My Report',          mimeType: 'application/vnd.google-apps.spreadsheet'      };      var media = {          mimeType: 'application/vnd.ms-excel',          body: require(path.resolve('src', 'files', 'excel', 'solargroup.xlsx'))      };      drive.files.create({          resource: fileMetadata,          media: media,          fields: 'id'      }, function (err, file: any) {          if (err) {              // Handle error              console.error(err);      } else {          console.log('File Id:', file.id);      }      });  }  

I received this error: enter image description here

https://stackoverflow.com/questions/66548228/upload-a-excel-file-with-google-drive-api March 09, 2021 at 09:54PM

没有评论:

发表评论