问题
so i am using this: https://github.com/google/google-api-nodejs-client#using-api-keys
here is the nodejs code:
router.get("/deals", function(req, res, next) {
var key = require('../gmail-a574e06ad196.json');
var jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
['https://www.googleapis.com/auth/gmail.readonly', 'https://mail.google.com/'], // an array of auth scopes
null
);
jwtClient.authorize(function (err, tokens) {
if (err) {
res.send('123');
return;
}
console.log('token is: ', tokens)
// Make an authorized request to list Drive files.
drive.users.labels.list({
auth: jwtClient,
userId: 'me'
}, function (err, resp) {
console.log(err)
res.send('123')
});
});
});
but once i hit that api, i got the following error: errors: [ { domain: 'global', reason: 'failedPrecondition', message: 'Bad Request' } ] }
I google around. found on some sites that said, the service account only work if you have G-Suite account, which is a paid account. My gmail account is a normal personal account. so no matter what i do, it just wont work?
- Is that true?
- What i am trying to do is, so i have a gmail account to collects newsletters, I want to create a nodejs api that returns/lists all emails from that account. I dont want oAuth, because really, no need to manually login. All i want is when page load, login automaically happens and the api returns list of emails, so everyone can see the list. Is there any other appoach of achieving this?
Thanks
回答1:
you can not use service account with a normal users Gmail account due to the fact that there is no way to delicate access to another user. you can only do it with gsuite.
you could consider going through the SMTP or IMAP server's directly
来源:https://stackoverflow.com/questions/49092338/nodejs-gmail-failedprecondition