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

查看:109
本文介绍了为什么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.

通过各种测试Gmail帐户不断发送电子邮件,我*(但不是100%肯定)认为浏览器界面搜索功能有一个不同的定义。似乎在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搜索有所不同?欢迎您提供Al提示!

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!

推荐答案

我怀疑这是之后的查询参数给你带来麻烦。 2015/11/04不是有效的ES5 ISO 8601日期。您可以尝试以下替代方案:< 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天全站免登陆