我想从我的Gmail下载整个收件箱(电子邮件正文文本和附件)。使用消息ID,我可以获得Gmail.Message
对象,但这些对象只包含片段(约200个字符)。如何使用API从Gmail收件箱获取完整邮件和附件?
对于C#,是否有一种方法可以使用Gmail API以XML格式获取整个收件箱?
我想从我的Gmail下载整个收件箱(电子邮件正文文本和附件)。使用消息ID,我可以获得Gmail.Message
对象,但这些对象只包含片段(约200个字符)。如何使用API从Gmail收件箱获取完整邮件和附件?
对于C#,是否有一种方法可以使用Gmail API以XML格式获取整个收件箱?
对于Gmail API请参考https://developers.google.com/gmail/api/v1/reference/users/messages/list#parameters
HTTP请求
GET https://www.googleapis.com/gmail/v1/users/userId/messages
请确保您在您的要求将正确的授权头。
据the documentation,您可以使用
GET https://www.googleapis.com/gmail/v1/users/userId/messages/id
这是你正在使用的电话吗?它说的默认格式为Full
:
“充分”:返回与有效域解析主体内容的完整的电子邮件数据;未使用原始字段。 (默认)
为了得到附件,你可以尝试 Users.messages.attachments:
GET https://www.googleapis.com/gmail/v1/users/userId/messages/messageId/attachments/id
但对于这一点,你将需要安装ID。您可能想要检查显示可用数据的User.messages overview,也许您可以尝试拨打Payload
电话?
查看API,您需要向/users/me/threads
发出请求,然后在users/me/threads/<id>
内发出body.data
值,该值为base 64编码。我不知道用C#API 100%,但我认为你会做这样的事情:
var request = service.Users.Threads.List("me");
var labels = request.Execute().Threads;
foreach(var thread in lables){
var threadReqeust = service.Users.Threads.Get("me", thread.Id);
var data = threadReqeust.Execute();
//you have your entire message now
}
(你做的一切注意,这是半pusudo代码,因为我没有检查这与Gmail的API )
(https://developers.google.com/gmail/api/v1/reference/users/threads/list) (https://developers.google.com/gmail/api/v1/reference/users/threads/get) “如果身体数据被包含在一个单独的附接的附接ID存在”。
另一种选择是始终使用IMAP(使用ImapX或同等产品)登录,并以这种方式收集数据,但使用API会更好。
它是我追随的一种方式。但是没有字段“body”只有“snippet” –
尝试查看请求中的格式属性(https://developers.google.com/gmail/api/v1/reference/users/threads/get) 也线程项目中的(消息)列表(https://developers.google。com/gmail/api/v1/reference/users/threads#resource-representations) –
如何配置Format属性?我发现格式属性: var getReq = UsersResource.MessagesResource.GetRequest.FormatEnum.Full; 但是如何使用方法Get?我必须使用服务。对? service.Users.Messages.Get(“我”,item.Id).Execute() - 但方法得到没有任何重载像格式第三个参数。 –
你准确的API调用是什么?你能提供HTTP请求吗? – gretro