Gmail Oauth API get message count

The new Gmail API now allows you to count the number of messages and unread emails inside a label. But I can't get it to work and have tried a lot of things. It's properly connected to Oauth, but can't get the account to work. I am using below code: -

$labelall = $service->users_labels->listUsersLabels('me');
        $labels = $labelall->getLabels();
     foreach ($labels as $label) {
         print 'Label with ID: ' . $label->getId() . ', 
Number of Messages:'.$label->getMessagesTotal().'<br/>';}


Can anyone please help? It renders the labels correctly, but the number of posts returns null.



source to share

1 answer

Not all fields are always set from the list () response - in which case you have to do Labels.Get () on the label you want to get.



All Articles