首页 > 解决方案 > google tasks api权限不足

问题描述

我按照步骤访问此处找到的 Google Tasks API ,安装了库,复制了 Python 代码,在我的计算机中执行了快速入门,并且成功了。

之后我更改了代码以编写任务,这是代码:

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

请注意,我将 SCOPE 更改为写入权限 ,但出现“权限不足”的错误消息。我怎么解决这个问题?

标签: pythongoogle-apis-explorergoogle-tasks-api

解决方案


好的,我找到了答案。问题是我第一次运行该程序时,它创建了一个具有只读访问权限的令牌文件。第二次运行该程序时,即使我更改了源代码中的范围,脚本仍然使用第一次运行时创建的旧令牌。解决方案是,在第二次运行之前删除令牌文件。


推荐阅读