我認爲你唯一的選擇是列出的信息與查詢after:<start_date> before:<end_date>
直到有在響應沒有nextPageToken
,然後坐總數:
function getMessageCount($service, $userId, $query) {
$pageToken = NULL;
$messages = array();
$opt_param = array(
'q' => $query
);
do {
try {
if ($pageToken) {
$opt_param['pageToken'] = $pageToken;
}
$messagesResponse = $service->users_messages->listUsersMessages($userId, $opt_param);
if ($messagesResponse->getMessages()) {
$messages = array_merge($messages, $messagesResponse->getMessages());
$pageToken = $messagesResponse->getNextPageToken();
}
} catch (Exception $e) {
print 'An error occurred: ' . $e->getMessage();
}
} while ($pageToken);
return count($messages);
}
如果你想獲得信息的數量在例如Friday, September 1, 2017 12:00:00 AM
和Sunday, October 1, 2017 12:00:00 AM
,你會這樣稱呼它:
$count = getMessageCount($service, 'me', 'after:1504224000 before:1506816000');