Messages.get响应

时间:2017-03-24 22:32:21

标签: php gmail-api

我对gmail api很新。我正在尝试编写一个可以使用php访问我的收件箱的脚本。我能够成功调用api但是当我使用get方法时,我在响应中没有收到任何有效负载。

$client = getClient();
$service = new Google_Service_Gmail($client);

$user = 'me';
$messages = $service->users_messages->listUsersMessages($user,["q"=>"is:unread"]);

foreach($messages as $message)
{
  print "\nMessage Id: " . $message->id . "\n";
  $messageObject = $service->users_messages->get($user,$message->id,["format"=>"full"]);
  print json_encode($messageObject);
}

我的一个回复供参考,如下:

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"}

我已经读过其他堆栈溢出线程和api文档,我应该能够使用$ messageObject-> getPayload()访问MessagePart对象,但由于响应甚至没有有效负载字段,它返回空。

有什么建议吗?

修改 我尝试检索的所有其他消息都有类似的响应。

当我尝试使用以下

向我发送电子邮件时
$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);

我收到以下输出

{"historyId":null,"id":"15b03f64b7261425","internalDate":null,"labelIds":["UNREAD","SENT","INBOX"],"raw":null,"sizeEstimate":null,"snippet":null,"threadId":"15b03f64b7261425"}

0 个答案:

没有答案