google 个任务 api 权限不足
google tasks api Insufficient Permission
我正在按照步骤访问找到的 Google 任务 API,here,
安装库,复制 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 更改为 write privilege
但是我收到一条错误消息 "Insufficient Permission"。
我该如何解决这个问题?
好的,我找到了答案。
问题是我第一次 运行ned 该程序时它创建了一个具有只读访问权限的令牌文件。
我第二次 运行 编译程序时,即使我更改了源代码中的范围,脚本仍然使用在第一次 运行 中创建的旧标记。
解决方案是,删除第二个 运行.
之前的令牌文件
我正在按照步骤访问找到的 Google 任务 API,here, 安装库,复制 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 更改为 write privilege 但是我收到一条错误消息 "Insufficient Permission"。 我该如何解决这个问题?
好的,我找到了答案。 问题是我第一次 运行ned 该程序时它创建了一个具有只读访问权限的令牌文件。 我第二次 运行 编译程序时,即使我更改了源代码中的范围,脚本仍然使用在第一次 运行 中创建的旧标记。 解决方案是,删除第二个 运行.
之前的令牌文件