-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
type: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.
Description
I'm trying to connect with the google API's for the first time, and when I attempt to make a request to the gmail API I'm getting a Precondition check failed error. I am using a service account authorization, not Oauth2 user consent. Things I've tried:
- Authorized "domain wide delegation" for the service account.
- Ensured the APP is trusted in the G suite account.
- Have also tried just returning the projectId from the API - and that works. So it is authorizing and connecting. It's when I try to make a request to gmail specifically that's giving me issue.
- Service account role is "owner"
This is adapted from a sample, but the sample did not use service account auth so I wasn't able to use the sample directly.
const path = require('path');
const {google} = require('googleapis');
const gmail = google.gmail('v1');
async function runSample() {
// Obtain user credentials to use for the request
const auth = new google.auth.GoogleAuth({
keyFile: path.resolve(__dirname, 'google-key.json'),
scopes: ['https://www.googleapis.com/auth/gmail.readonly'],
});
google.options({auth});
const res = await gmail.users.messages.list({userId: 'me'}); // have tried with my gsuite email address as well
console.log(res.data);
return res.data;
}
if (module === require.main) {
runSample().catch(console.error);
}
module.exports = runSample;returning Error: Precondition check failed.
njt1982, gauravkrp, zbjornson, robert-bor, logicxd and 18 more
Metadata
Metadata
Assignees
Labels
type: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.