gpt4 book ai didi

gmail-api - GMail v1 API Users.messages 结果与逻辑 AND/OR 上的 Web UI 不同

转载 作者:行者123 更新时间:2023-12-05 07:48:08 25 4
gpt4 key购买 nike

我正在使用以下查询:

No Man's Sky

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

GMail 网页界面

Web UI

请注意,对话 View 已禁用:

Conversation Setting

如果启用对话 View ,Web UI 会返回 9 个线程;使用线程 API,我得到 7 个线程。


API 浏览器位于 https://developers.google.com/gmail/api/v1/reference/users/messages/list :

API Explorer

{  
"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 个结果的子集)。

更新:

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

这确实留下了如何使用 API 复制原始搜索的问题;是否必须运行 3 个查询然后只获取所有 3 个中返回的结果?当您开始处理复杂的查询时,这会变成一件繁琐的解析工作。

With literals

更新 2

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

用于测试的代码:

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 请求的批处理和一些其他特定于应用程序的例程。它使用以下方法检索批处理中的每组项目:

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 中的两个实例(它们在同一个线程中)突出显示了命中:

enter image description here

另一个在电子邮件中分别点击了 No ManSky(注意不是 Man 的)。

更新 3

回到 Web UI,我决定对搜索词 Man's 进行一些测试。

在 Web UI 中,我获得了数百次点击:

Web UI Man's

对于 “Man's”,我得到 11 次匹配:

Web UI Quoted Man's

API 与引用的 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 结果的方法。

最佳答案

我用我自己的 Gmail 试了一下,我发现有些电子邮件是在一个线程中找到的。

这是我的例子:

我使用了单词 time tracker 作为我的主题,Gmail 用户界面为我提供了 4 封电子邮件的结果。但是如果你算上总的结果,它给了我一共 12 个结果。 A 6 封,B 3 封,C 2 封,D 1 封邮件。

enter image description here

所以如果我使用请求

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}

Try it part在 Gmail API 中,

enter image description here

它会像在 GMail UI 中那样给我一个包含 12 个 ID 的结果。

enter image description here

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

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

关于gmail-api - GMail v1 API Users.messages 结果与逻辑 AND/OR 上的 Web UI 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38960331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com