如何在 Google App Engine 中使用任务队列 API?

How to use Task Queue API in Google App Engine?

我在 Google Cloud Platform 的 my_project 中启用了任务队列 API。

并且我为 Web 应用程序生成了 OAuth 客户端 ID,并将重定向 URL 设置为 https://my_project.appspot.com/oauth2callback
然后我将 (decorator.callback_path, decorator.callback_handler()) 添加到 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)

当我执行上面的代码时,我收到以下错误信息。

https://www.googleapis.com/tasks/v1/users/@me/lists?alt=json 返回 "Insufficient Permission">

如何修复错误?

@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)