2

I develop a little command-line app to bring google tasks, but return all tasks in a specified task list does not return completed tasks, wish showCompleted is true by default

So I tried many times in Live API and only uncompleted tasks are returned, see by your self: https://developers.google.com/tasks/v1/reference/tasks/list

For those who did not understand go to you Gmail and add a non concluded task and a concluded one, then go to the live API and test it, you will see the concluded task doesn't appear even if you set showCompleted to True! How in the online version of Google Tasks can they get the tasks completed?

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

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

1 Answers1

4
  • You want to retrieve the task list of with and without "completed" using Python.
  • You have already been able to use Tasks API.

If my understanding is correct, how about this modification?

In order to retrieve the completed tasks, please use the property of showHidden as follows. The property of showCompleted is True as default.2

Modified script:

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

for task in tasks['items']:
  print task['title']
  print task['status']
  print task['completed']
To:
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')

Reference:

If I misunderstood your question and this was not the result you want, I apologize.

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • Adding an if to check if the key "completed" exists in the dict does nothing, because just try this: go to you Gmail add a non concluded task and a concluded one, then go to the live API and test it, you will see the concluded task doesn't appear even if you set showCompleted to True! sorry for my bad english –  Jun 12 '19 at 22:32
  • ok I realized, you are correct, when completing a task it automatically passes to hidden, and if showHidden and showCompleted equals to True, then this makes your code valid! –  Jun 12 '19 at 22:39
  • @Micael Dias Thank you for replying and confirming it. I'm glad your issue was resolved. Thank you, too. – Tanaike Jun 12 '19 at 22:40
  • I know that I should not use the comments as a publicity mode, but since it solved my problem, I'll let you know the project that is behind this piece of code, it's just to learn python and it needs many improvements, but I think is something useful so here goes https://github.com/aimproxy/bandog –  Jun 12 '19 at 22:44
  • @Micael Dias Thank you for your additional information. – Tanaike Jun 12 '19 at 22:44