GMail v1 API Users.messages结果与Web UI的逻辑AND/OR不同 [英] GMail v1 API Users.messages results differ from Web UI on logical AND/OR

查看:44
本文介绍了GMail v1 API Users.messages结果与Web UI的逻辑AND/OR不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下查询:

没有人的天空

No Man's Sky

与API Explorer和C#应用程序相比,我从Web UI获得的结果不同.

I get different results from the Web UI compared with the API Explorer and my C# application.

注意,对话视图已禁用:

Note, conversation view is disabled:

如果启用对话视图,则Web UI返回9个线程;使用线程API,我有7个线程.

If I enable conversation view, I get 9 threads returned by the Web UI; using the thread API, I get 7 threads.

{  
 "messages": [  
  {  
   "id": "15686dcf7989e60f"  
  },  
  {  
   "id": "1566bce4412a439d"  
  },  
  {  
   "id": "156327e51b979f48"  
  },  
  {  
   "id": "1560f0caf9297ab9"  
  },  
  {  
   "id": "155f01dba1c3ad77"  
  },  
  {  
   "id": "1538bce006a95a84"  
  },  
  {  
   "id": "15342e9d99b4d3f6"  
  }  
 ]  
}  

我在C#应用程序中看到的结果与API资源管理器相同. API和Web UI之间似乎断开了连接. Web UI返回10个结果,API仅返回这10个结果中的7个(我已经确认它们是10个结果中的一部分).

I see the same results as the API explorer in my C# application. There seems to be a disconnect here between the API and Web UI. The Web UI returns 10 results, which the API returns only 7 of those 10 (I have verified that they're a subset of the 10 manually).

事实证明,API将查询视为文字.在Web UI中用引号将查询引起来的结果与API相同.

It turns out that the API treats the query as a literal. Surrounding the query in the Web UI with quotation marks gives the same results as the API.

这确实存在如何使用API​​复制原始搜索的问题;一个人必须先运行3个查询,然后仅取所有3个查询中返回的结果?当您开始进行复杂的查询时,这将成为解析工作的一部分.

This does leave the question of how to replicate the original search using the API; does one have to run 3 queries and then take only the results returned in all 3? When you start getting into complex queries that becomes a bit of a parsing chore.

我尝试通过分别运行3个ANDed术语然后复制结果(其中消息ID是所有3个查询的结果集,并获得与API调用相同的7个结果)来复制Web UI结果.

I've tried to replicate the Web UI results by running the 3 ANDed terms individually and then pulling results where the message ID is the result set of all 3 queries and I get the same 7 results as the API call.

用于测试的代码:

var service = GMailServiceManager.Instance.Service;
var resultsNo = GMailUtils.GetItems(service, null, "No", true);
var resultsMans = GMailUtils.GetItems(service, null, "Man's", true);

var resultsSky = GMailUtils.GetItems(service, null, "Sky", true);

var anded = from nos in resultsNo.Items
              from manses in resultsMans.Items
                from skys in resultsSky.Items
                where nos.Id == manses.Id && nos.Id == skys.Id
                select nos.Id;

GMailUtils.GetItems()仅处理API请求和某些其他特定于应用程序的例程的批处理.它使用以下内容检索批处理中的每组项目:

GMailUtils.GetItems() simply handles batching of the API requests and some other app-specific routines. It uses the following to retrieve each group of items in the batch:

UsersResource.MessagesResource.ListRequest request = service.Users.Messages.List("me");
request.Q = search;
request.Fields = "messages(id),nextPageToken";
request.PageToken = pageToken;
// Logging and batching here
...
  request.Execute();
...

我现在不知道Web UI如何与其他点击匹配.点击突出显示在两个实例中位于www.no-mans-sky.com上(它们在同一线程中):

I now have no idea how the Web UI comes up with the other hits; the hit highlighting is on www.no-mans-sky.com in two instances (they're in the same thread):

No ManSky上的其他命中分别通过电子邮件(请注意不是Man的命中).

The other hits on No Man and Sky individually in an e-mail (note not Man's).

回到Web UI,我决定对搜索字词Man's做一些测试.

Going back to the Web UI I decided to do a little testing on the search term Man's.

在网络用户界面中,我获得了几百次点击:

In the web UI, I get several hundred hits:

对于"Man's",我得到11次点击:

For "Man's" I get 11 hits:

API与引用的Web UI匹配:

The API matches the quoted Web UI:

{
 "messages": [
  {
   "id": "15686dcf7989e60f"
  },
  {
   "id": "1566bce4412a439d"
  },
  {
   "id": "156327e51b979f48"
  },
  {
   "id": "1560f0caf9297ab9"
  },
  {
   "id": "155f01dba1c3ad77"
  },
  {
   "id": "1538bce006a95a84"
  },
  {
   "id": "15342e9d99b4d3f6"
  },
  {
   "id": "13da4a6d7a4159b2"
  },
  {
   "id": "13da4a502eca7dff"
  },
  {
   "id": "12e70fbf3d655ac8"
  },
  {
   "id": "1278adc3ed72f6a8"
  }
 ]
}

基于此,看来该API的查询被视为字符串文字而不是Web-UI风格的查询.对我来说似乎是个错误,因为我找不到使用API​​重现Web UI结果的方法.

Based on this it would appear that the API's query is treated as a string literal rather than Web-UI-style query. Seems like a bug to me, as I cannot find a way to reproduce the Web UI's results using the API.

推荐答案

我在自己的Gmail上进行了尝试,发现在单个线程中发现了一些电子邮件.

I tried it with my own Gmail, and I observed that some emails are found in a single thread.

这是我的例子:

我用时间跟踪器作为主题,Gmail UI给了我4封电子邮件的结果.但是,如果您将总结果计算在内,则总共可以得到12个结果.从A发送6封邮件,从B发送3封邮件,从C发送2封邮件,从D发送1封电子邮件.

I used the word time tracker as my subject, and the Gmail UI gives me a result of 4 emails. But if you count the total results, it gives me a total of 12 results. 6 from A, 3 from B, 2 from C and 1 email from D.

因此,如果我使用请求

GET https://www.googleapis.com/gmail/v1/users/example%40google.com/messages?q=subject%3A(time+tracker)&fields=messages(id%2CthreadId)&key={YOUR_API_KEY}

试试吧在Gmail API中,

or the Try it part in the Gmail API,

它会给我12个ID的结果,就像在GMail UI中一样.

It will give me a result of 12 IDs like in the GMail UI.

查看上图,您会发现所有属于同一线程的电子邮件都具有相同的threadId.

Looking at the illustration above, you will notice that all emails belonging to the same thread have identical threadId.

因此,请尝试使用threadId确定在您的请求中找到的电子邮件数量.如果我误解了这个问题,请告诉我.

So try to use the threadId to determine the number of emails found in your request. Please someone tell me if I misunderstood this question.

这篇关于GMail v1 API Users.messages结果与Web UI的逻辑AND/OR不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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