【问题标题】:Get list of emails (Sender's Email, Subject and Body) between given dates through Gmail API in Python通过 Python 中的 Gmail API 获取给定日期之间的电子邮件列表(发件人的电子邮件、主题和正文)
【发布时间】:2021-01-02 21:35:34
【问题描述】:

我正在开展一个项目,该项目需要通过 Gmail API 进行 JSON 文件响应,其中包含给定日期之间所有电子邮件(发件人信息、主题和正文)的列表。然后将根据需要处理该 JSON 文件。
我不确定如何生成一个请求,该请求可以通过 Python 使用 Gmail API 为我提供所需的 JSON 文件。
我是初学者,请帮帮我。

【问题讨论】:

    标签: python json gmail-api


    【解决方案1】:

    假设您已经通过 OAuth 并构建了服务(如果没有,请检查 the quickstart),您必须执行以下操作:

    user_id = "me"
    searchFilter = "after:2020/01/01 before:2020/10/01"
    messages = service.users().messages().list(userId=user_id, q=searchFilter).execute()
    
    • 列出消息时,仅填充idthreadId。为了获得所有这些消息的完整消息资源,您应该遍历它们并为每条消息调用users.messages.get,使用它的id
    for message in messages["messages"]:
        messageId = message["id"]
        message = service.users().messages().get(userId=user_id, id=messageId).execute()
    

    参考:

    【讨论】:

      猜你喜欢
      • 2020-01-13
      • 2021-04-27
      • 2018-08-25
      • 2014-09-07
      • 2020-09-04
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 2019-08-04
      相关资源
      最近更新 更多