为什么在 gmail API 中搜索与在 gmail 网站中搜索返回的结果不同? [英] Why does search in gmail API return different result than search in gmail website?

查看:40
本文介绍了为什么在 gmail API 中搜索与在 gmail 网站中搜索返回的结果不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 gmail API 来搜索来自用户的电子邮件.我创建了以下搜索查询:

I'm using the gmail API to search emails from users. I've created the following search query:

ticket after:2015/11/04 AND -from:me AND -in:trash

当我在 Gmail 的浏览器界面中运行此查询时,我收到 11 条消息(如预期).但是,当我在 API 中运行相同的查询时,我只收到 10 条消息.我用来查询 gmail API 的代码是用 Python 编写的,如下所示:

When I run this query in the browser interface of Gmail I get 11 messages (as expected). When I run the same query in the API however, I get only 10 messages. The code I use to query the gmail API is written in Python and looks like this:

searchQuery = 'ticket after:2015/11/04 AND -from:me AND -in:trash'
messagesObj = google.get('/gmail/v1/users/me/messages', data={'q': searchQuery}, token=token).data
print messagesObj.resultSizeEstimate  # 10

我将同一封邮件发送到另一个 gmail 地址,并从该电子邮件地址对其进行了测试,(令我惊讶的是)它确实显示在具有该其他电子邮件地址的 API 搜索中,因此问题不在于电子邮件本身.

I sent the same message on to another gmail address and tested it from that email address and (to my surprise) it does show up in an API-search with that other email address, so the trouble is not the email itself.

在通过各种 test-gmail 帐户无休止地发送电子邮件后,我*认为(但不是 100% 确定)浏览器界面搜索功能对 "me" 有不同的定义.似乎在 API 搜索中它不包括来自具有相同名称的电子邮件地址的电子邮件,而这些结果实际上包含在浏览器搜索的结果中.例如:如果 "Pete Kramer"petekramer@icloud.com 发送一封电子邮件到 pete@gmail.com(两者都有他们的名字)设置为 "Pete Kramer") 它将显示在浏览器搜索中,而不会显示在 API 搜索中.

After endlessly emailing around through various test-gmail accounts I *think (but not 100% sure) that the browser-interface search function has a different definition of "me". It seems that in the API-search it does not include emails which come from email addresses with the same name while these results are in fact included in the result of the browser-search. For example: if "Pete Kramer" sends an email from petekramer@icloud.com to pete@gmail.com (which both have their name set to "Pete Kramer") it will show in the browser-search and it will NOT show in the API-search.

有人可以确认这是问题所在吗?如果是这样,有没有办法绕过它以获得与浏览器搜索返回的结果相同的结果?或者其他人知道为什么 gmail 浏览器搜索的结果与 gmail API 搜索不同?欢迎所有提示!

Can anybody confirm that this is the problem? And if so, is there a way to circumvent this to get the same results as the browser-search returns? Or does anybody else know why the results from the gmail browser-search differ from the gmail API-search? Al tips are welcome!

推荐答案

我怀疑是 after 查询参数给您带来了麻烦.2015/11/04 不是有效的 ES5 ISO 8601 日期.您可以尝试替代 after:<time_in_seconds_since_epoch>

I would suspect it is the after query parameter that is giving you trouble. 2015/11/04 is not a valid ES5 ISO 8601 date. You could try the alternative after:<time_in_seconds_since_epoch>

# 2015-11-04 <=> 1446595200

searchQuery = 'ticket AND after:1446595200 AND -from:me AND -in:trash'
messagesObj = google.get('/gmail/v1/users/me/messages', data={'q': searchQuery}, token=token).data
print messagesObj.resultSizeEstimate  # 11 hopefully!

这篇关于为什么在 gmail API 中搜索与在 gmail 网站中搜索返回的结果不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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