在C#中从messages.get获取更多数据 [英] Getting more data from messages.get in C#

查看:49
本文介绍了在C#中从messages.get获取更多数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不仅要获取尝试使用Gmail API检索的邮件文本数据的片段,而且还有很多麻烦.这是我正在使用的测试代码:

I'm having trouble getting more than just the snippet for text data for the message I am trying to retrieve using the Gmail API. Here is the piece of test code I am working with:

    public string GetMail()
    {
        GmailService service = (GmailService)HttpContext.Current.Session["service"];

        Message messageFeed = service.Users.Messages.List("me").Execute().Messages.First();

        UsersResource.MessagesResource.GetRequest getReq = new UsersResource.MessagesResource.GetRequest(service, "me", messageFeed.Id);

        getReq.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Full;
        Message message = getReq.Execute();

        return message.Raw;
    }

由于某种原因,当我调用message.Raw时,它返回null.我可以检索其他属性,例如format = minimum设置将基于我正在使用的API操场示例.

For some reason, when I call message.Raw, it is returning null. I am able to retrieve other properties as what the format=minimal setting would based off of the API playground example I was playing with.

但是,在我的代码中,我将枚举格式设置为完整",但仍无法检索消息的完整数据.

However in my code, I am setting the format enum to "full", yet I am still unable to retrieve the full data of the message.

我在这里完全错过了什么吗?

Am I completely missing something here?

推荐答案

似乎您正在混淆格式和响应类型.如果要将原始消息作为Message.raw中的字符串,则需要设置:

Seems like you're mixing up formats and response types. If you want the raw message as a string in Message.raw then you need to set:

getReq.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw;

如果要返回解析的消息(在有效载荷"字段中),则可以像使用一样使用Full的getReq.Format.

If you want the parsed message back (in the "payload" field) then you can use getReq.Format of Full like you have.

可接受的值为:

  • 已满":在有效负载字段中返回已解析的电子邮件消息内容,而未使用原始字段. (默认)

  • "full": Returns the parsed email message content in the payload field and the raw field is not used. (default)

最小":仅返回电子邮件元数据,例如标识符和标签,不返回电子邮件标头,正文或有效载荷.

"minimal": Only returns email message metadata such as identifiers and labels, it does not return the email headers, body, or payload.

原始":以字符串形式返回原始字段中的整个电子邮件内容,并且不使用有效负载字段.其中包括标识符,标签,元数据,MIME结构和较小的正文部分(通常小于2KB).

"raw": Returns the entire email message content in the raw field as a string and the payload field is not used. This includes the identifiers, labels, metadata, MIME structure, and small body parts (typically less than 2KB).

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

这篇关于在C#中从messages.get获取更多数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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