Python Gmail API不会将labelIds参数传递给List方法 [英] Python Gmail API won't pass labelIds Parameter to List method

查看:51
本文介绍了Python Gmail API不会将labelIds参数传递给List方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试设置Python脚本,该脚本涉及查询Gmail帐户中的未读邮件.理想情况下,我想使用Gmail API的列表"方法和可选的查询参数过滤功能,以过滤标签ID为"UNREAD"的邮件.

I've been trying to get a Python script set up that involves querying a Gmail account for unread messages. Ideally I'd like to make use of the Gmail API's "list" method with the optional query parameter filtering for messages with the labelId of "UNREAD".

当我在Google网站上进行测试时( https://developers.google.com/gmail/api/v1/reference/users/messages/list ),它可以正常运行.

When I test this out on Google's site (https://developers.google.com/gmail/api/v1/reference/users/messages/list) , it works properly.

但是在我的脚本中,labelId参数似乎未正确传递,并且我的输出始终是消息的完整列表.

But within my script, the labelId parameter seems to not be passed correctly and my output is always the full list of messages.

这是我现在得到的代码行:

Here's the line of code I've got right now:

results = service.users().messages().list(userId='me', labelIds='UNREAD').execute()

这将返回收件箱中的所有邮件,而不是过滤为仅UNREAD.

This returns all messages in the inbox, not filtered to UNREAD only.

我遇到过一些文档,这些文档涉及与可选查询(Gmail API列表方法中的"q"参数)相似的问题,但不适用于labelIds.

I've come across some documentation on people having a similar issue with the optional queries ('q' parameter in the Gmail API list method) but not for labelIds.

有人有这个问题的经验吗?

Does anyone have any experience with this problem?

推荐答案

此修改如何?我认为您的情况有几种模式.

How about this modification? I think that there are several patterns for your situation.

results = service.users().messages().list(userId='me', labelIds=['UNREAD']).execute()

例如,如果要检索收件箱中的未读邮件,则可以使用 userId ='me',labelIds = ['UNREAD','INBOX'] userId='me',labelIds = ['UNREAD'],q ='in:inbox'.

For example, if you want to retrieve the unread messages in the inbox, you can use userId='me', labelIds=['UNREAD', 'INBOX'] and userId='me', labelIds=['UNREAD'], q='in:inbox'.

results = service.users().messages().list(userId='me', q='is:unread').execute()

例如,如果要检索收件箱中的未读邮件,可以使用 userId ='me',q ='in:inbox是:unread'.

For example, if you want to retrieve the unread messages in the inbox, you can use userId='me', q='in:inbox is:unread'.

如果我误解了你的问题,对不起.

If I misunderstand your question, I'm sorry.

这篇关于Python Gmail API不会将labelIds参数传递给List方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆