Batch fetching messages performance

前端 未结 4 1606
你的背包
你的背包 2021-02-10 09:27

I need to get the last 100 messages in the INBOX (headers only). For that I\'m currently using the IMAP extension to search and then fetch the messages. This is done with two re

4条回答
  •  清歌不尽
    2021-02-10 10:03

    In addition to MaK you can perform multiple batch requests using the google-api-php-client and Google_Http_Batch()

            $optParams = [];
            $optParams['maxResults'] = 5;
            $optParams['labelIds'] = 'INBOX'; // Only show messages in Inbox
            $optParams['q'] = 'subject:hello'; // search for hello in subject
    
            $messages = $service->users_messages->listUsersMessages($email_id,$optParams);
    
            $list = $messages->getMessages();
    
                $client->setUseBatch(true);
    
                $batch = new Google_Http_Batch($client);                
    
                foreach($list as $message_data){
    
                    $message_id = $message_data->getId();
    
                    $optParams = array('format' => 'full');
    
                    $request = $service->users_messages->get($email_id,$message_id,$optParams);
    
                    $batch->add($request, $message_id);                 
                }
    
                $results = $batch->execute();
    

提交回复
热议问题