[英]How to Find the Attachment ID for Getting an Email Using the Gmail API?
我使用 Python 通过 Gmail-API 访问 Gmail。 我想通过一个简单的调用来下载电子邮件的附件,为此您必须传递三个参数:ID、消息 ID 和用户 ID。 我有最后两个,但我在哪里可以找到第一个? 文档说这是附件的 ID,所以我在 Gmail 中尝试了“显示原件”选项,但没有成功。 API 不断返回错误消息“无效的附件令牌”。 在哪里可以找到附件 ID?
https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get
为了检索特定消息的附件ID
,您必须通过Users.messages.get获取消息资源,并从该响应中检索附件的ID
。
此ID
可以在相应消息部分的body
属性中找到(您可以使用filename
属性来了解每个ID
对应哪个附件),如本示例所示:
{
"payload": {
"parts": [
{
"filename": {attachment_filename},
"body": {
"attachmentId": {attachment_id}
// other body properties
},
// other part properties
},
// other parts
],
// other payload properties
},
// other message properties
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.