I want to write a script that uses the Gmail API to download all attachments from all emails with labelID Label_41.
I completed the instruction at https://developers.google.com/gmail/api/quickstart/php
Using the API I expected listUsersMessages(...)->getMessages()
to return all emails with label Label_41.
$client = getClient();
$service = new Google_Service_Gmail($client);
$user = 'me';
$labels = array('labelIds' => array('Label_41'));
$messagesResponse = $service->users_messages->listUsersMessages($user, $labels);
$messages = $messagesResponse->getMessages();
foreach ($messages as $message) {
echo 'Message with ID: ' . $message->getId();
echo $message->getLabelIds();
if($message->getLabelIds() == null) echo " (NO LABEL) ";
echo "\n";
}
However, all the emails that I got here have no label assigned to them, as my terminal output shows. What have I done wrong here?