【问题标题】:How to Find the Attachment ID for Getting an Email Using the Gmail API?如何找到使用 Gmail API 获取电子邮件的附件 ID?
【发布时间】:2020-02-24 22:13:44
【问题描述】:

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

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

【问题讨论】:

  • 您是否通过索引gmail attachment via index 访问附件?
  • 是的,但我不明白解决方案。在控制台中执行代码不起作用。也不通过 Firefox 打开链接。

标签: python gmail-api google-apis-explorer


【解决方案1】:

为了检索某条消息的附件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
}

参考:

【讨论】:

    猜你喜欢
    • 2018-11-03
    • 2021-01-27
    • 2022-01-25
    • 2019-02-10
    • 2021-03-04
    • 2023-03-14
    • 2021-04-08
    • 2019-08-27
    • 1970-01-01
    相关资源
    最近更新 更多