如何过滤 Google Api 收件箱只读主要邮件?
How to filter the Google Api inbox to read only the main messages?
我制作了一个脚本来检查我的收件箱中是否有新电子邮件,但它 returns 来自主要、社交和促销框的电子邮件 (Gmail),但我只想阅读来自主框。
这是我的 IA 的脚本
# Call the Gmail API to fetch INBOX
results = service.users().messages().list(userId='me',labelIds = ['INBOX', 'UNREAD']).execute()
messages = results.get('messages', [])
if not messages:
frase = 'Sem novas mensagens na caixa de email'
a = Pesquise(frase)
a.fala(frase)
else:
for message in messages:
msg = service.users().messages().get(userId='me', id=message['id']).execute()
payld = msg['payload'] # get payload of the message
headr = payld['headers'] # get header of the payload
for one in headr: # getting the Subject
if one['name'] == 'Subject':
msg_subject = remover_acentos(one['value'])
else:
pass
frase = 'Hugo, novo email na caixa de entrada, ' + msg_subject
a = Pesquise(frase)
a.fala(frase)
sleep(600)
except Exception as err:
print err
我只想让脚本读取主框,而不是主框、社交框和促销框。
基于 SGC 的 ,您可以在 Users.messages: list
上添加以下 q
参数:
in:inbox is:unread -category:(promotions OR social)
结果将类似于:
{
"messages": [
{
"id": "169f891015afd26b",
"threadId": "169f891015afd26b"
},
{
"id": "169f67bfu70eed28",
"threadId": "169f67bf5d0eed28"
},
{
"id": "169f65c4bea507b9",
"threadId": "169f27c4bea507b9"
},
{
"id": "169ef58fd53f6c1d",
"threadId": "169ef58fd53f6c1d"
},
{
"id": "169eecy7846c17ca",
"threadId": "169eecy7846c17ca"
},
{
"id": "169ea5df63c40128",
"threadId": "169ea5df63c40128"
}
],
"resultSizeEstimate": 6
}
你可以试试这个here。
我制作了一个脚本来检查我的收件箱中是否有新电子邮件,但它 returns 来自主要、社交和促销框的电子邮件 (Gmail),但我只想阅读来自主框。
这是我的 IA 的脚本
# Call the Gmail API to fetch INBOX
results = service.users().messages().list(userId='me',labelIds = ['INBOX', 'UNREAD']).execute()
messages = results.get('messages', [])
if not messages:
frase = 'Sem novas mensagens na caixa de email'
a = Pesquise(frase)
a.fala(frase)
else:
for message in messages:
msg = service.users().messages().get(userId='me', id=message['id']).execute()
payld = msg['payload'] # get payload of the message
headr = payld['headers'] # get header of the payload
for one in headr: # getting the Subject
if one['name'] == 'Subject':
msg_subject = remover_acentos(one['value'])
else:
pass
frase = 'Hugo, novo email na caixa de entrada, ' + msg_subject
a = Pesquise(frase)
a.fala(frase)
sleep(600)
except Exception as err:
print err
我只想让脚本读取主框,而不是主框、社交框和促销框。
基于 SGC 的 Users.messages: list
上添加以下 q
参数:
in:inbox is:unread -category:(promotions OR social)
结果将类似于:
{
"messages": [
{
"id": "169f891015afd26b",
"threadId": "169f891015afd26b"
},
{
"id": "169f67bfu70eed28",
"threadId": "169f67bf5d0eed28"
},
{
"id": "169f65c4bea507b9",
"threadId": "169f27c4bea507b9"
},
{
"id": "169ef58fd53f6c1d",
"threadId": "169ef58fd53f6c1d"
},
{
"id": "169eecy7846c17ca",
"threadId": "169eecy7846c17ca"
},
{
"id": "169ea5df63c40128",
"threadId": "169ea5df63c40128"
}
],
"resultSizeEstimate": 6
}
你可以试试这个here。