I enabled Task Queue API in my_project of Google Cloud Platform.
And I generated OAuth client-id for web-application and set redirect URL to https://my_project.appspot.com/oauth2callback.
And I add (decorator.callback_path, decorator.callback_handler()) to webapp2.WSGIApplication.
from oauth2client.contrib.appengine import OAuth2DecoratorFromClientSecrets
from googleapiclient.discovery import build
decorator = OAuth2DecoratorFromClientSecrets(
'my.json', scope='https://www.googleapis.com/auth/tasks.readonly')
@decorator.oauth_aware
def get_google_client_credential_tasks(self):
http = decorator.http()
service_tasks = build('tasks', 'v1', http=http)
temp_str = ''
tasklists = service_tasks.tasklists().list().execute(http=http)
for tasklist in tasklists[0]['items']:
temp_str += tasklist['title']
self.response.write(temp_str)
When I execute the above code, I got the following error message.
https://www.googleapis.com/tasks/v1/users/@me/lists?alt=json returned "Insufficient Permission">
How do I fix the error?
@decorator.oauth_aware
def get_google_client_credential_tasks(self):
if decorator_google_client.has_credentials():
http = decorator.http()
service_tasks = build('tasks', 'v1', http=http)
temp_str = ''
tasklists = service_tasks.tasklists().list().execute(http=http)
for tasklist in tasklists[0]['items']:
temp_str += tasklist['title']
self.response.write(temp_str)
else:
url = decorator_google_client.authorize_url()
self.redirect(url)