I'm pretty new to the gmail api. I'm trying to write a script that can access my inbox with php. I'm able to successfully make calls to the api but when I use the get method, I don't receive any payload in the response.
$client = getClient();
$service = new Google_Service_Gmail($client);
$user = 'me';
$messages = $service->users_messages->listUsersMessages($user,["q"=>"is:unread"]);
foreach($messages as $message)
{
print "
Message Id: " . $message->id . "
";
$messageObject = $service->users_messages->get($user,$message->id,["format"=>"full"]);
print json_encode($messageObject);
}
One of my responses, for reference, is as follows:
Message Id: 15af8a0461fe2b11
{"historyId":"1028","id":"15af8a0461fe2b11","internalDate":"1490229938000","labelIds":["UNREAD","INBOX"],"raw":null,"sizeEstimate":4831,"snippet":"Hi Brian Get the official Gmail app The best features of Gmail are only available on your phone and tablet with the official Gmail app. Download the app or go to gmail.com on your computer or mobile","threadId":"15af8a0461fe2b11"}
I've read on other stack overflow threads and the api documentation that I should be able to access the MessagePart object with $messageObject->getPayload() but as the response doesn't even have a payload field, it returns null.
Any advice?
Edit: All other messages I attempt to retrieve have a similar response.
When I try to send an email to myself with the following
$message_object = new Google_Service_Gmail_Message();
$encoded_message = rtrim(strtr(base64_encode("From: 'Brian Z'
<brian@mydomain.example>
Subject: Test Message
To: 'Brian Z' <brian@mydomain.example>
Test Message"), '+/', '-_'), '=');
$message_object->setRaw($encoded_message);
$test = $service->users_messages->send($user, $message_object);
print json_encode($test);
I receive the following output
{"historyId":null,"id":"15b03f64b7261425","internalDate":null,"labelIds":["UNREAD","SENT","INBOX"],"raw":null,"sizeEstimate":null,"snippet":null,"threadId":"15b03f64b7261425"}