I'm using the following query:
No Man's Sky
I get different results from the Web UI compared with the API Explorer and my C# application.
GMail Web UI
Note, conversation view is disabled:
If I enable conversation view, I get 9 threads returned by the Web UI; using the thread API, I get 7 threads.
API Explorer at https://developers.google.com/gmail/api/v1/reference/users/messages/list:
{
"messages": [
{
"id": "15686dcf7989e60f"
},
{
"id": "1566bce4412a439d"
},
{
"id": "156327e51b979f48"
},
{
"id": "1560f0caf9297ab9"
},
{
"id": "155f01dba1c3ad77"
},
{
"id": "1538bce006a95a84"
},
{
"id": "15342e9d99b4d3f6"
}
]
}
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).
UPDATE:
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.
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.
UPDATE 2
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.
Code used to test:
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()
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();
...
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):
The other hits on No
Man
and Sky
individually in an e-mail (note not Man's).
Update 3
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:
For "Man's"
I get 11 hits:
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"
}
]
}
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.
I tried it with my own Gmail, and I observed that some emails are found in a single thread.
Here is my example:
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.
So if I use the request
or the Try it part in the Gmail API,
It will give me a result of 12 IDs like in the GMail UI.
Looking at the illustration above, you will notice that all emails belonging to the same thread have identical
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.