nodejs gmail失败 [英] nodejs gmail failedPrecondition

查看:53
本文介绍了nodejs gmail失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在使用它: https://github.com/google/google-api-nodejs-client#using-api-keys

这是nodejs代码:

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')
      });
    });
});

但是一旦我点击了该api,就会出现以下错误:错误:[{域:全局",原因:"failedPrecondition",消息:错误请求"}]}

but once i hit that api, i got the following error: errors: [ { domain: 'global', reason: 'failedPrecondition', message: 'Bad Request' } ] }

我在Google周围搜索.在某些网站上发现,服务帐户仅在您拥有G-Suite帐户(即付费帐户)时才有效.我的gmail帐户是普通的个人帐户.所以不管我做什么,都行不通?

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. 是真的吗?
  2. 我想做的是,所以我有一个可以收集新闻通讯的gmail帐户,我想创建一个nodejs api,该API返回/列出该帐户的所有电子邮件.我不需要oAuth,因为实际上,不需要手动登录.我想要的只是页面加载,登录自动发生并且api返回电子邮件列表,以便每个人都可以看到该列表.还有其他实现此目标的方法吗?

谢谢

推荐答案

您无法将服务帐户与普通用户的Gmail帐户一起使用,原因是无法轻松访问其他用户.您只能使用gsuite.

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.

您可以考虑直接通过SMTP或IMAP服务器

you could consider going through the SMTP or IMAP server's directly

这篇关于nodejs gmail失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆