我想使用PYTHON和google API从自定义标签中读取邮件。但是,我遇到了将标签从收件箱更改为自定义标签的错误
label_id_one = 'AW'
label_id_two = 'UNREAD'
unread_msgs = GMAIL.users().messages().list(userId='me',labelIds=[label_id_one, label_id_two]).execute()
获取此错误:
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\googleapiclient\discovery.py", line 272, in _retrieve_discovery_doc
raise HttpError(resp, content, uri=actual_url)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://gmail.googleapis.com/$discovery/rest?version=v2 returned "The request cannot be identified with a project. Please pass a valid API key with the request.">
答案 0 :(得分:0)
我删除了labelID并添加了q参数,如下所示。这里的“测试”是我在Gmail中创建的文件夹。
unread_msgs = GMAIL.users().messages().list(userId='me',q='in:test is:unread').execute()