Reputation: 393
Im using this example, with my custom parameters to get only certain messages. My issue is that maxResults is not working, and i cant find how to exclude messages from certain domain. This is my custom function:
public function listMessages($userId) {
$client= $this->getClient();
$service = new Google_Service_Gmail($client);
$pageToken = NULL;
$messages = array();
$opt_param = array(
'maxResults' => 20,
'q'=>'!in:chats'
);
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);
foreach ($messages as $message) {
print 'Message with ID: ' . $message->getId() . '<br/>';
}
return $messages;
}
Im still getting ALL my messages (except hangout messages, this is the only filter working)
Upvotes: 0
Views: 358
Reputation: 116869
Maxrows is used for paging. If the result would return 1000 rows and you set max rows to 100 you would have to page over the nextpagetoken 10 times to get all of the results.
Setting maxrows to 20 wont help you as I believe the min maxrows is something like 100 (I believe this is the default with most of the Google APIs). You will never get fewer then 100 rows unless there are less then 100 rows generated by your request.
try 'q'=>'[email protected]'
Upvotes: 0