1

I'm following the steps to access the Google Tasks API found here, installed the libraries, copied the code for Python, executed the quickstart in my computer and it worked.

After that I changed the code to write a task, Here is the code:

from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file as oauth_file, client, tools

# If modifying these scopes, delete the file token.json.
SCOPES = 'https://www.googleapis.com/auth/tasks'


def main():
    store = oauth_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('tasks', 'v1', http=creds.authorize(Http()))

    tasklist_id = "theidofmygoogletasklist"
    task = {
        'title': 'Study Python',
        'notes': '',
        'due': ''
    }

    # Call the Tasks API
    results = service.tasks().insert(tasklist=tasklist_id, body=task).execute()
    print(result['id'])


if __name__ == '__main__':
    main()

Note that I changed the SCOPE to write privilege But I'm getting an error saying "Insufficient Permission". How can I solve this problem?

user24312
  • 73
  • 8

1 Answers1

1

Ok I found the answer. The problem is that the first time I runned the program it created a token file with readonly access. The second time I runned the program, even though I changed the scope in the source code, the script was still using the old token that was created in the first run. The solution was, delete the token file before the second run.

user24312
  • 73
  • 8
  • Three years later and I encountered this exact issue except using C#. This was my problem as well and this solution worked for me. – Jason Nov 21 '21 at 14:40