如何在Google App Engine中使用Task Queue API?

时间:2018-05-19 15:53:42

标签: python api google-app-engine task-queue

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

我为网络应用程序生成了OAuth客户端ID,并将重定向网址设置为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返回"权限不足">

如何修复错误?

1 个答案:

答案 0 :(得分:1)

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