Reputation: 23
I'm trying to get the message count of my Gmail Inbox from C#, but it turns out that the message counts are not returned for ANY of my labels.
The following returns my label names (both personal and system created) just fine, but the the respective message counts are always null. I've tried all of the message counts: MessagesUnread, MessagesTotal, ThreadsUnread, ThreadsTotal, and always get "No" below.
ListLabelsResponse response = service.Users.Labels.List("me").Execute();
foreach (Label label in response.Labels)
{
Console.Write("{0}, has messages? ", label.Name);
if (label.MessagesUnread.HasValue)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
What am I doing wrong?
Upvotes: 0
Views: 90
Reputation: 1
label Properties each label resource only contains an id, name, messageListVisibility, labelListVisibility, and type. The labels.get method can fetch additional label details such as MessagesUnread. https://googleapis.dev/dotnet/Google.Apis.Gmail.v1/latest/api/Google.Apis.Gmail.v1.Data.ListLabelsResponse.html
Upvotes: 0
Reputation: 23
Apparently the Google API is too lazy to fill in the count details on the List method. Instead I tried the Get...
Label rsp = service.Users.Labels.Get("me", "INBOX").Execute();
..and everything shows up nicely in the Label object. Problem solved.
Upvotes: 2