【问题标题】:How to exclude "Deleted messages" from Historylist如何从历史列表中排除“已删除邮件”
【发布时间】:2020-01-26 01:30:18
【问题描述】:

我正在根据最后一个 history_id 同步用户的电子邮件,并且工作正常。 但有时它不起作用并显示消息未找到错误。 我检查并发现,它正在同步从收件箱中删除或退回的消息。

我在 $opt_pram 数组 'historyTypes'=>'messageAdded' 中添加了一个参数,但它仍然可以获取所有已删除消息的消息。 我也尝试过 labelIds= INBOX 但它不起作用。

$opt_param = array('historyTypes'=>'messageAdded','startHistoryId' => $history_id,'maxResults'=>100);

$pageToken = NULL;
$histories = array();

do {
    try {
        if ($pageToken) {
            $opt_param['pageToken'] = $pageToken;
        }
        $historyResponse = $service->users_history->listUsersHistory($user, $opt_param);
        if ($historyResponse->getHistory()) {
            $histories = array_merge($histories, $historyResponse->getHistory());
            $pageToken = $historyResponse->getNextPageToken();
        }
    } catch (Exception $e) {
        print 'An error occurred: ' . $e->getMessage();
    }
} while ($pageToken);

$histories 中,它也包含已删除的消息。

我正在寻找可以获取所有有效/现有消息的解决方案。

【问题讨论】:

    标签: php gmail-api


    【解决方案1】:

    'historyTypes'=>'messageAdded' 将显示自创建相应的 startHistoryId 以来添加的所有消息,即使这些消息已被荒谬地删除。

    作为一种解决方法,我建议您对 'historyTypes'=>'messageDeleted' 进行第二次查询,然后比较相应查询响应中包含的消息 Id,并且只同步 'historyTypes'=>'messageAdded' 查询中包含的消息,而不是 @987654325 中包含的消息@查询。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-20
      • 2012-12-05
      • 2013-03-31
      • 2015-12-10
      • 2017-10-01
      • 2014-06-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多