Gmail API getting all Gmail Inbox messages limits to 500

99封情书 提交于 2020-01-04 14:07:08

问题


I am trying to get all the inbox messages in the Gmail API, but it's limiting to 500 per request. I would like to get all the messages, and the current messages in the repository is 1600+ but I am only able to get 500 on one request.

$service = new Google_Service_Gmail($client);
$user = 'me';

$params = array(
    'labelIds' => 'INBOX', 
    'maxResults' => 20000
);

$last_date = mysqli_fetch_array($query);
extract($last_date);


$date = date_create($latest);
$date->modify('-1 day');
$filter_date = date_format($date, 'Y/m/d');
$params['q'] = 'in:inbox after:'.$filter_date ;

$messages = $service->users_messages->listUsersMessages( $user, $params );
$list = $messages->getMessages();
//$list only has 500 messages returned to me.

回答1:


Just to add clarity, this is what's happening. You performed a Users.messages: list which fetches 1600+ messages. Now I'm pretty sure Gmail fetched those 1600+ messages but it can only display 500 messages at a time.

If you want to access the next 501-1000 messages, you need to use the nextPageToken which comes with every successful response. That goes on for the next 1001-1500 messages and so forth.

You can read the nextPageToken mentioned here in Gmail Request body



来源:https://stackoverflow.com/questions/43269704/gmail-api-getting-all-gmail-inbox-messages-limits-to-500

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!