dongmanzui8486 2017-03-24 22:32
浏览 31

Messages.get响应中没有有效负载字段

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"}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题