nodejs gmail failedPrecondition

…衆ロ難τιáo~ 提交于 2021-01-28 13:31:31

问题


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?

  1. Is that true?
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!