【问题标题】:I am unable to retrieve the message by its id in gmail-api我无法通过 gmail-api 中的 id 检索邮件
【发布时间】:2019-10-16 18:52:55
【问题描述】:

所以我创建了一个带有两个方法 checkInbox() 和 getMail() 的类 Check。

checkInbox() 检索所有邮件,getMail(msgId) 将检索带有输入 Id 的邮件。

checkInbox() 工作正常,但 getMail() 方法提供与 checkInbox() 相同的输出,即列出所有邮件而不是返回请求的邮件。

class Check{

    constructor(auth){
        this.me = 'mygmailid';
        this.gmail = google.gmail({version: 'v1', auth});
        this.auth = auth;
    }

    checkInbox(){
        this.gmail.users.messages.list({
            userId: this.me
        }, (err, res) => {
            if(!err){
                console.log(res.data);
            }
        })
    }

    getMail(msgId){
        this.gmail.users.messages.get({
            'userId': this.me,
            'id': msgId
        }, (err, res) => {
            if(!err){
                console.log(res);
            }
        });
    }

}

var obj = new dem(auth);
obj.getMail('someRandomIdNumber');

我没有附加授权码,因为它可以正常工作。导入导出类也没有错误。

【问题讨论】:

    标签: javascript node.js ecmascript-6 google-api gmail-api


    【解决方案1】:

    这正是您获取 gmail 消息应该执行的操作:

      const response = await this.gmail.users.messages.get({
        auth: this.oAuth2Client,
        userId: this.gmailAddress,
        id: messageId,
        format: 'full'
      })
    

    你可以找到整个实现here。它是 Gmail-API 的轻量级包装器

    【讨论】:

      猜你喜欢
      • 2019-02-12
      • 2016-07-26
      • 1970-01-01
      • 2014-10-14
      • 2022-10-25
      • 1970-01-01
      • 2018-09-13
      • 2019-03-13
      • 2020-05-21
      相关资源
      最近更新 更多