我想從我的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