在PHP中,我使用Gmail api获取客户端的gmail收件箱。
使用
Array ( ['maxResults'] => 50, ['labelIds'] => INBOX, ['q'] => is:unread)
我正在搜索邮箱/ gmail中的未读电子邮件,但是我收到了一封标有
的电子邮件[labelIds] => Array([0] => Label_2 [1] => SENT).
gmail如何将这封电子邮件标识为unread
?我可以根据什么来突出显示这封unread
电子邮件?我的第二个问题是该电子邮件带有SENT
标签,它如何出现在INBOX
中?
$service = new Google_Service_Gmail($client);
$batch = new Google_Http_Batch($client);
$userId='me';
$threads = array();
$pageToken = NULL;
$param = array();
$getPageToken = $getParam('pageToken');
if ($getPageToken && $getPageToken!='') {
$param['pageToken'] = $getPageToken;
$pageToken = $getPageToken;
}
if($getParam('limit'))
$param['maxResults']=$getParam('limit');
else
$param['maxResults'] = 50;
if($getParam('in')) {
$this->view->in=$getParam('in');
$param['labelIds'] = strtoupper($this->view->in);
}
else
$param['labelIds'] = 'INBOX';
$search = "";
$read = $getParam('read_status');
if($read && (@$read=='read'||$read=='unread'))
$search = 'is:'.$read;
if($getParam('search')) {
$this->view->search = $getParam('search');
$search .= " ".$this->view->search;
}
if($search)
$param['q'] = $search;
$threadsResponse=$this->gmailApi->get_threads($service,$userId,$param);
if($threadsResponse) {
$threads=$threadsResponse->getThreads();
$this->view->next_page=$threadsResponse->getNextPageToken();
$client->setUseBatch(true);
foreach ($threads as $key => $val) {
$thread = $service->users_threads->get($userId, $val->id,['format' => 'full', 'metadataHeaders' => ['From','Date','Subject']]);
$batch->add($thread, "mail-".$val->id);
}
$results = $batch->execute();
$threads=$this->gmailApi->get_batch_messages($service,$userId,$results);
谁能告诉我这是不是here(https://issuetracker.google.com/issues/135166258)产生的问题
答案 0 :(得分:0)
您只搜索未读的电子邮件。如果您想要未读和收件箱标签,请尝试使用
q = label:unread label:inbox
将来,最简单的测试gmail搜索的方法是在gmail Web应用程序中,您可以在那里找到所需的搜索结果,然后将其复制到q中。
答案 1 :(得分:0)
您检索带有标签“收件箱”的所有线程,然后检索这些线程的所有消息。
请注意,线程同时包含传入和传出消息。
因此它将包含标签“收件箱”(用于传入消息),但
代替查询
$this->gmailApi->get_threads($service,$userId,$param);
您需要使用
$service->users_messages->listUsersMessages($userId, $param);
将labelIds[]
指定为该方法的可选参数。
q
参数和labelIds
“ INBOX”作为查询的线程,则结果将包含所有包含至少一个未读的线程收件箱中显示消息。q
“ is:unread”和labelIds
“ INBOX”的消息(不是线程)根据您的代码示例代码段:
//the following code works only if setUseBatch() is set to false
$client->setUseBatch(false);
$messagesResponse = $service->users_messages->listUsersMessages($userId, $param);
if ($messagesResponse) {
$messages = $messagesResponse->getMessages();
foreach ($messages as $key => $val) {
print ("\n unread message id ".$val->id."\n");
}
}