【问题标题】:Query search in Gmail API doesn't work as web versionGmail API 中的查询搜索不适用于网络版本
【发布时间】:2018-02-18 18:04:37
【问题描述】:

我正在尝试提取带有某种星形颜色的邮件(Gmail API)。 例如,蓝星。

def listMessagesMatchingQuery(service, user_id='me', query=''):
    try:
        response = service.users().messages().list(userId=user_id,
                                                   q=query).execute()
        print(response)
        messages = []
        if 'messages' in response:
            messages.extend(response['messages'])

        while 'nextPageToken' in response:
            page_token = response['nextPageToken']
            response = service.users().messages().list(userId=user_id, q=query,
                                                   pageToken=page_token).execute()
            messages.extend(response['messages'])
        return messages

    except errors.HttpError as error:
        print('An error occurred: %s' % error)


print(listMessagesMatchingQuery(GMAIL, query="has:blue-star"))

而且它不像网页版那样工作,它返回 0 封电子邮件。另一个查询效果很好(尝试了“from:...”、“has:attachment”、“has:drive”、“before:...”、“after:...”等)。找不到解决方案,我需要按星星的颜色对电子邮件进行排序。

【问题讨论】:

  • 在 Gmail API 中查询超级明星是相当棘手的。您可能需要将其更改为例如l:^ss_cb 代表蓝星,例如 explained here
  • 非常感谢。这有助于@Tholle

标签: python gmail-api


【解决方案1】:

在 Gmail API 中查询超级明星非常棘手。您可能需要将其更改为例如l:^ss_sb 代表蓝星,比如explained in this blogpost

has:yellow-star <=> l:^ss_sy
has:blue-star <=> l:^ss_sb 
has:red-star <=> l:^ss_sr 
has:orange-star <=> l:^ss_so
has:green-star <=> l:^ss_sg
has:purple-star <=> l:^ss_sp
has:red-bang <=> l:^ss_cr
has:yellow-bang <=> l:^ss_cy
has:blue-info <=> l:^ss_cb
has:orange-guillemet <=> l:^ss_co
has:green-check <=> l:^ss_cg
has:purple-question <=> l:^ss_cp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多