因此,我使用两个方法checkInbox()和getMail()创建了一个类检查。
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');我没有附加授权码,因为它工作得很好。此外,导入和导出类时也没有错误。
发布于 2019-11-10 21:10:39
这正是您获取gmail消息时应该做的事情:
const response = await this.gmail.users.messages.get({
auth: this.oAuth2Client,
userId: this.gmailAddress,
id: messageId,
format: 'full'
})您可以找到完整的实现here。它是Gmail-API的一个轻量级包装器
https://stackoverflow.com/questions/56389719
复制相似问题