Gmail API not returning correct emails compared to Gmail web UI for date queries

一个人想着一个人 提交于 2019-12-19 19:18:04

问题


The results differ between the Gmail api and Gmail web ui when using the standard query format as described here - https://support.google.com/mail/answer/7190.

The issue is specifically for the parameters after/before and newer/older. For example the following Gmail api query "after:2015/11/19 before:2015/11/20" returns different results compared with running that same query in the Gmail web ui. The web ui looks correct whereas the api returns emails from the next day (20th). Possibly a timezone conversation problem?

Checking past questions I see something similiar here how to use GMAIL API query filter for datetime (the server processes the queries as PST time). If this is the case it might be worth updating the docs or think about a possible solution.

Steps to reproduce the problem.

  1. Have some mail in a gmail account covering the dates below. Inc days after and before.
  2. Run after:2015/11/19 before:2015/11/20 in a Gmail web ui.
  3. Query the Gmail api with "after:2015/11/19 before:2015/11/20" for the q parameter using https://developers.google.com/gmail/api/v1/reference/users/messages/list
  4. Compare results. (I had differences when running these steps against a UK Gmail account)

Should only see emails from the 19th, but I see emails dated the 19th AND 20th when using the api. The web ui works as expected and only returns emails dated the 19th.

FYI: I was also using other query parameters such as "from: example@example.com" in conjuction with before/after or newer/older params. I wanted to simplify the bug report / question.

Also: The api queries I was making with a node module called node-gmail-api. Checking the code the endpoint being used is 'messages' code:

body: 'GET ' + api + '/gmail/v1/users/me/messages/' + m.id + fields + '\n'

Is the problem that 'messages' and not 'messages/list' endpoint is being called? As per answer to this question? - Why does search in gmail API return different result than search in gmail website?

Is this a bug / feature? Is there a workaround such as using epoch ms. (also not in the docs as I can see)

Thanks


回答1:


You can list the messages with second accuracy if you would like:

q = after:<start_of_day_in_seconds> AND before:<end_of_day_in_seconds>

So e.g. from Wed, 25 Nov 2015 00:00:00 GMT to Wed, 25 Nov 2015 23:59:59 GMT would be:

q = after:1448409600 AND before:1448495999


来源:https://stackoverflow.com/questions/33912834/gmail-api-not-returning-correct-emails-compared-to-gmail-web-ui-for-date-queries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!