如何从“消息"列表中获取“有效载荷"属性? Gmail API [英] How can I get 'payload' property from the Messages list? Gmail API

查看:67
本文介绍了如何从“消息"列表中获取“有效载荷"属性? Gmail API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Node的新手,我想获取有关我的gmail消息的信息,例如谁编写了该消息和文本. 我遵循快速入门示例并编写以下代码,但输出中仅包含"id"和"threadId"字段.

I'm new in node, and I want to get info about my gmail messages, like who's wrote the message and the text. I follow quickstart exemple and write the following code, but there are just 'id' and 'threadId' field in output.

function listMessages(auth) {
    var gmail = google.gmail('v1');
    gmail.users.messages.list({
        auth: auth,
        userId: 'me'
    }, function(err, response) {
        if (err) {
            console.log('The API returned an error: ' + err);
            return;
        }
        var messages = response.messages;
        if (messages.length == 0) {
            console.log('No messages found.');
        } else {
            console.log('Messages:');
            for (var i = 0; i < messages.length; i++) {
                var message = messages[i];
                console.log(message);
            }
        }
    });
}

有人可以解释一下吗?谢谢.

Could somebody explain me? Thanks.

推荐答案

messages.list() API根据设计仅返回消息ID和线程ID.如果您需要获取这些消息的详细信息,则需要进行另一个API调用messages.get()以获得每条消息的特定详细信息.

messages.list() API returns only the message IDs and thread IDs by design. If you need to get details of those messages you need to make another API call messages.get() to get specific details of each message.

API参考: https://developers.google.com/gmail/api/v1/reference/users/messages/get

API reference: https://developers.google.com/gmail/api/v1/reference/users/messages/get

虽然这可行,但您可能希望了解一下GMail的批处理操作,这些操作允许在一个呼叫中获取消息的详细信息(尽管有限制).

While this will work, you may want to have a look at GMail's batch operations which allow getting details of messages in one call (with limitations though).

Google批量指南: https://developers.google.com/gmail/api/guides/batch

Google's guide on batch: https://developers.google.com/gmail/api/guides/batch

类似的查询已在SO处得到解答:

Similar queries have been answered here at SO:

  • Gmail API all messages
  • Gmail API Users.messages: list

这篇关于如何从“消息"列表中获取“有效载荷"属性? Gmail API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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