I am struggling a lot to get my authentication to work for Google drive api.
This is my current code.
const drive = google.drive({
version: 'v3',
auth: new google.auth.GoogleAuth({
keyFile: 'google-cloud-credentials.json',
scopes: ['https://www.googleapis.com/auth/drive.file'],
}),
});
No matter what I try, I get the error "ENOENT: no such file or directory, open '/var/task/google-cloud-credentials.json'"
I've also tried the following:
keyFile: path.resolve(__dirname, 'google-cloud-credentials.json'),
keyFile: './google-cloud-credentials.json',
keyFile: '../google-cloud-credentials.json',
keyFile: '../../google-cloud-credentials.json',
I should mention that I'm also deploying with with Serverless but in the past I've been able to get this to work.
CodePudding user response:
So I found in the type definition for GoogleAuth that you can simply use credentials
which takes the body of the credentials rather than keyFile
which takes the path.
After that I just simply had to import JSON into my file and add it there.
CodePudding user response:
that's not how you Auth. that's just creating google Auth object. you must fill it with credentials or it will do nothing.
maybe read the readme again. there's a standard implementation of oauth there. also feel free to ask a follow up