javascript - 我无法通过 gmail-api 中的 id 检索邮件
问题描述
所以我用两个方法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');
我没有附上授权码,因为它工作正常。导入和导出类也没有错误。
解决方案
这正是获取 gmail 消息应该执行的操作:
const response = await this.gmail.users.messages.get({
auth: this.oAuth2Client,
userId: this.gmailAddress,
id: messageId,
format: 'full'
})
你可以在这里找到整个实现。它是 Gmail-API 的轻量级包装器
推荐阅读
- javascript - 需要使锚标记转到特定的ID,同时为固定标头腾出空间
- powerbi - 基于 ID 和日期计算平均值的 DAX 函数
- reactjs - Redux 对 .splice() 的不良影响
- android - Android 6.0.1 上的 Flutter Camera 视频录制抛出错误
- video - AMP 在向下滚动时停止视频
- javascript - 以二进制格式下载字节数组
- ios - Swift 制作一个泛型函数
- oop - 带有元表的 Lua OOP,从文件加载函数的问题
- powershell - 在抑制输出 PowerShell 时在 Out-Null 之前设置变量
- sql - 雪花中的任务 - 多个 SQL