Skip to content

Instantly share code, notes, and snippets.

@jrdnrc
Last active March 22, 2017 09:12
Show Gist options
  • Save jrdnrc/83f91c55b9374bfbb6ffa72f30557fc8 to your computer and use it in GitHub Desktop.
Save jrdnrc/83f91c55b9374bfbb6ffa72f30557fc8 to your computer and use it in GitHub Desktop.
Retrieving a message
<?php declare(strict_types = 1);
// assuming Google_Client is already configured, and assigned to $client
// $currentUser is the currently authenticated user
$gmail = new Google_Service_Gmail($client);
$googleUserId = $currentUser->getGoogleId();
$response = $gmail->users_messages->listUsersMessages(
$googleUserId,
[
'q' => 'your gmail search query',
]
);
$rawData = [];
foreach ($response as $messageResponse) {
$rawData[$messageResponse->getId()] = $gmail->users_messages->get(
$googleUserId,
$messageResponse->getId(),
[
'format' => 'raw',
]
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment