为什么在Gmail中搜索API与Gmail网站的搜索返回不同的结果? [英] Why does search in gmail API return different result than search in gmail website?
问题描述
我使用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条消息。在code我用它来查询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搜索它不包括来自电子邮件地址具有相同的名称,而这些结果实际上包括在浏览器的搜索的结果的电子邮件。例如:如果皮特克莱默
从 petekramer@icloud.com
将电子邮件发送到 pete@gmail.com
(这两者都有自己的名称设置为皮特克莱默
),它会在浏览器的搜索表明,它不会显示在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!
推荐答案
我怀疑这是给你的麻烦了在
查询参数。 2015年11月4日是不是一个有效的ES5的ISO 8601日期。你可以尝试另外的后:LT; 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屋!