我正在尝试分析我的 25k 多封电子邮件,类似于此处的帖子:http: //beneathdata.com/how-to/email-behavior-analysis/
虽然提到的脚本使用了 IMAP,但我正在尝试使用 Gmail API 来实现它以提高安全性。我正在使用 Python(和 Pandas 进行数据分析),但这个问题更普遍地适用于 Gmail API 的使用。
从文档中,我可以使用以下方式阅读电子邮件:
msgs = service.users().messages().list(userId='me', maxResults=500).execute()
然后使用循环访问数据:
for msg in msgs['messages']:
m_id = msg['id'] # get id of individual message
message = service.users().messages().get(userId='me', id=m_id).execute()
payload = message['payload']
header = payload['headers']
for item in header:
if item['name'] == 'Date':
date = item['value']
** DATA STORAGE FUNCTIONS ETC **
但这显然很慢。除了遍历每条消息之外,我还必须多次调用 list() API 来循环浏览所有电子邮件。
有没有更高性能的方法来做到这一点?例如要求 API 只返回数据而不是所有不需要的消息信息。
谢谢。