我正在按照下面的步骤访问Google Tasks,找到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()请注意,我将作用域更改为write privilege,但收到一个错误消息“权限不足”。我该如何解决这个问题?
发布于 2018-08-08 21:16:21
好了,我找到答案了。问题是,当我第一次运行程序时,它创建了一个只读访问的令牌文件。第二次运行程序时,即使我更改了源代码中的作用域,脚本仍然使用第一次运行时创建的旧令牌。解决方案是,在第二次运行之前删除令牌文件。
https://stackoverflow.com/questions/51672528
复制相似问题