如何使用Gmail API查找用于获取电子邮件的附件ID?

2024-06-26 14:30:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Python通过Gmail API访问Gmail。我想打一个简单的电话下载电子邮件附件,为此,您必须传递三个参数:ID、messageid和UserID。我有最后两个,但第一个在哪里?医生说这是附件的ID,所以我在Gmail中尝试了“显示原创”选项,但没有成功。API不断返回错误消息“无效附件令牌”。我在哪里可以找到附件ID

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


Tags: httpsapiid消息附件参数电子邮件选项
1条回答
网友
1楼 · 发布于 2024-06-26 14:30:50

为了检索某个消息附件的ID,您必须通过Users.messages.get获取消息资源,并从该响应中检索附件的ID

这个ID可以在the corresponding message partbody属性中找到(您可以使用类似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
}

参考资料:

相关问题 更多 >