【问题标题】:users().messages().list() seems to be capped out at 500 messagesusers().messages().list() 似乎上限为 500 条消息
【发布时间】:2020-11-10 07:53:44
【问题描述】:
def main():
   
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
    creds = tools.run_flow(flow, store)
service = build('gmail', 'v1', http=creds.authorize(Http()))

# Call the Gmail API to fetch INBOX
results = service.users().messages().list(userId='me',labelIds = ['Label_21'], maxResults=600).execute()
messages = results.get('messages', [])
print (len(messages))

我正在阅读我每天收到的这些特别标记的消息,以便将它们存档在我自己的自定义应用程序中。我的 gmail 帐户中有超过 500 条此类消息。但是,即使我将 maxResults 更改为 600,该 api 似乎也被限制为 500 条最新消息。

还有其他人有这个问题吗?有人可以帮忙吗?我似乎在文档中找不到任何关于 .user.messages.list 输出限制的信息。 Image for clarification/proof

【问题讨论】:

    标签: python jupyter gmail-api


    【解决方案1】:
    results = service.users().messages().list(userId='me',labelIds = ['Label_21'], maxResults=600).execute()
    

    刚刚发现list()方法中的查询参数。我可以在 q='before:yyyy/mm/dd' 中添加它以从丢失的日期中提取结果。这将导致以下结果

    results = service.users().messages().list(userId='me',labelIds = ['Label_21'], maxResults=600, q='before:yyyy/mm/dd').execute()
    

    【讨论】:

      猜你喜欢
      • 2018-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-12
      相关资源
      最近更新 更多