如何避免从Gmail Rest API获取邮件中的附件数据

时间:2016-09-18 18:17:19

标签: gmail-api

如何通过get message request从Gmail Rest API加载附件数据。

至少使用fields参数我们可以避免加载少量字段,但是当我想加载邮件正文时,附件数据也会像IMAP一样出现在身体上

1 个答案:

答案 0 :(得分:0)

您没有像在IMAP中那样获得附件。您将获得一个attachmentId,您必须在附加请求中使用{ "id": "1573ec1aa0976b42", "threadId": "1573ec1aa0976b42", "labelIds": [ "SENT", "INBOX", "IMPORTANT", "UNREAD" ], "snippet": "", "historyId": "939514", "internalDate": "1474226662000", "payload": { "mimeType": "multipart/related", "filename": "", "headers": [ ... ], "body": { "size": 0 }, "parts": [ { "mimeType": "multipart/alternative", "filename": "", "headers": [ { "name": "Content-Type", "value": "multipart/alternative; boundary=94eb2c0d3cba8637a2053ccd2461" } ], "body": { "size": 0 }, "parts": [ { ... }, { "partId": "1", "mimeType": "image/png", "filename": "Screen Shot", "headers": [ ... ], "body": { "attachmentId": "ANGjdJ-bmCvsIaV-4KfALXzVV_D567w4i6ksLnwIZhLAl3VXCE335663UbmOLC_vbLrCFusNtnWVpdTv3i88uR482kFwLZqAcwmI7C5gFlamob2aK4-lqAPlCZs17jtCQR9y5Mt4nnpP_Kg64N9qgXbDF0E2vYnEw4xwtEKEo4fRIAbc94ZjjfynFD832mh1B37XFMt-bYw9wkNv24xBife0koBNYpKs-gGLJkfu2EoZouqunGDX9ry1jq2jW2AClWcFXPXvgRBMjUcoRDPtvb9LLLrBhDjU1hu6r1Ibc3c2BSoBogT8QyIp2VUCuFU", "size": 1511996 } } ] }, "sizeEstimate": 1513185 } 来获取附件。

我刚给自己发了一条附有图片的信息。这就是API的响应:

attachmentId

如您所见,它只包含override func viewDidLoad() { super.viewDidLoad() self.view.layoutIfNeeded() // <- This will update your initial view frames updateUI() } 且没有实际的附件数据。