首页 > 解决方案 > 返回所有任务不返回已完成的任务

问题描述

我开发了一个带google任务的命令行小应用,但是返回指定任务列表中的所有任务不返回已完成的任务,希望showCompleted默认为true

所以我在 Live API 中尝试了很多次,只返回未完成的任务,请自行查看:https ://developers.google.com/tasks/v1/reference/tasks/list

不明白的去Gmail给你添加一个未结束的任务和一个结束的任务,然后去live API测试一下,你会发现即使你把showCompleted设置为True,也没有出现结束的任务!他们如何在 Google Tasks 的在线版本中完成任务?

tasks = service.tasks().list(tasklist='@default').execute()

for task in tasks['items']:
  print task['title']
  print task['status']
  print task['completed']

标签: pythongoogle-tasks-apigoogle-tasks

解决方案


  • 您想使用 Python 检索有无“已完成”的任务列表。
  • 您已经能够使用 Tasks API。

如果我的理解是正确的,那么这个修改呢?

为了检索已完成的任务,请使用以下属性showHidden。的属性showCompleted为默认值True。2

修改后的脚本:

从:
tasks = service.tasks().list(tasklist='@default').execute()

for task in tasks['items']:
  print task['title']
  print task['status']
  print task['completed']
至:
tasks = service.tasks().list(tasklist='@default', showHidden=True).execute()  # Modified
for task in tasks['items']:
    print(task['title'])
    print(task['status'])
    if 'completed' in task:  # Added
        print(task['completed'])
    else:
        print('not completed')

参考:

如果我误解了您的问题并且这不是您想要的结果,我深表歉意。


推荐阅读