2

I am trying to use apiGoogle Node.js client library to access the Google Drive API so I can upload some files to my drive account.

My code so far:

var drive = google.drive({ version: 'v3' });
drive.apiKey = "API_KEY"
drive.setScope = "https://www.googleapis.com/auth/drive.file"

drive.files.create({
    resource: {
        name: 'text.text',
        mimeType: 'text/plain',
        parents:['1ATscm2nsE9KpjA66iXHB9jnMrbyik7PP']
    },
    media: {
        mimeType: 'text/plain',

        body: fs.createReadStream('files/text.text')

    }
});

Errors:

 errors: 
   [ { domain: 'global',
       reason: 'required',
       message: 'Login Required',
       locationType: 'header',
       location: 'Authorization' } ] }

Can anybody help to resolve this issue?

abielita
  • 13,147
  • 2
  • 17
  • 59
Mhmd Backer Shehadi
  • 559
  • 1
  • 12
  • 30

1 Answers1

0

You may refer with this thread. Make sure that you are sending access_token={your oauth2 access token} and not key={your key} for an access token. You may check this documentation for more information.

abielita
  • 13,147
  • 2
  • 17
  • 59