Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python GMail api用户().history().list返回';下一个getoken';,但是没有';历史';领域_Python_Gmail_Gmail Api - Fatal编程技术网

Python GMail api用户().history().list返回';下一个getoken';,但是没有';历史';领域

Python GMail api用户().history().list返回';下一个getoken';,但是没有';历史';领域,python,gmail,gmail-api,Python,Gmail,Gmail Api,我使用GMail API来检索已更改消息的列表,这对几页历史记录很好——但有时当返回nextPageToken时,它用于检索下一页,该页返回时没有history字段。未引发任何HttpError results = self.service.users ().history ().list (userId = self.account, startHistoryId = start).execute () if 'history' in results: yield results['his

我使用GMail API来检索已更改消息的列表,这对几页历史记录很好——但有时当返回
nextPageToken
时,它用于检索下一页,该页返回时没有
history
字段。未引发任何
HttpError

results = self.service.users ().history ().list (userId = self.account, startHistoryId = start).execute ()
if 'history' in results:
  yield results['history']

while 'nextPageToken' in results:
  pt = results['nextPageToken']
  results = self.service.users ().history ().list (userId = self.account, startHistoryId = start, pageToken = pt).execute ()
  yield results['history'] # this fails with missing 'history' member.

如果我正确理解这个问题,你需要在历史页面上看到没有结果

while 'nextPageToken' in response:
    page_token = response['nextPageToken']
    response = gcon.users().messages().list(userId='me', pageToken=page_token).execute()
    if response['resultSizeEstimate'] is 0:
        break
    email.extend(response['messages'])
return email
我想这会有帮助的

if response['resultSizeEstimate'] is 0:
    break

你是否期待某个结果,但却没有?如果真的没有什么可显示的呢?如果没有更多可显示的内容,那么就不应该有
nextPageToken
。这就是我如何知道我已经到达了列表的末尾。如果我得到一个
nextpGetOken
,但没有更多的结果,没有任何错误,我不相信某些东西没有因为某个地方的错误而被遗漏-因为这是增量更新,我可能会在下一次增量更新时跳过那些缺失的更新。可能会看到?@boardrider:这种情况很少发生(千次或百万次请求中有一次),这里有完整的示例(底部示例):我记不太清楚,但我也不认为有
resultSizeEstimate
字段。无论如何,这似乎不太可靠。这不是整个查询的结果吗?而且返回了结果,只是
nextPageToken
表示有更多的结果,但没有。