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



我在Google Cloud Platform my_project启用了Task Queue 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 返回"权限不足>

如何修复此错误?

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

最新更新