Gmail API how to get labels ThreadsUnread

826 views Asked by At

how can i to get labels ThreadsUnread when excuting LabelsResource.ListRequest?

trying to get the ThreadsUnread property when i'm excuting the Google.Apis.Gmail.v1.UsersResource.LabelsResource.ListRequest but it comes with null value.

This is my code:

     Google.Apis.Gmail.v1.UsersResource.LabelsResource.ListRequest labelReq = service.Users.Labels.List("me");

    IList<Google.Apis.Gmail.v1.Data.Label> labels = labelReq.Execute().Labels;

what do i need to ask in the request the ThreadsUnread or MessagesUnread value?

There is a property in the request that called "fields". it can be set with a string. but where can i find what is the options of that string?

2

There are 2 answers

2
ReyAnthonyRenacia On

Use the Users.labels.get. In the try-it section do this:

GET https://www.googleapis.com/gmail/v1/users/userId/labels/id

userId: me

id: INBOX

and execute, the response would looke something like:

{
 "id": "INBOX",
 "name": "INBOX",
 "messageListVisibility": "hide",
 "labelListVisibility": "labelShow",
 "type": "system",
 "messagesTotal": 1808,
 "messagesUnread": 1610,
 "threadsTotal": 454,
 "threadsUnread": 323
}

and there's the "threadsUnread": 323 you're looking for.

0
dearsina On

At the time of writing (March, 2019), you cannot get counts when doing a list. You have to subsequently request the details of each label to get the detail. Very slow, costly and frankly unnecessary. The equivalent Microsoft Graph API doesn't have this limitation.