python - 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 更改为写入权限 ,但出现“权限不足”的错误消息。我怎么解决这个问题?
解决方案
好的,我找到了答案。问题是我第一次运行该程序时,它创建了一个具有只读访问权限的令牌文件。第二次运行该程序时,即使我更改了源代码中的范围,脚本仍然使用第一次运行时创建的旧令牌。解决方案是,在第二次运行之前删除令牌文件。
推荐阅读
- c++ - 在 C++ 中实现 dwrite 以绘制字体字形导致 nullptr 错误
- ios - 如何在 Mac Catalyst 应用程序中检测颜色面板的颜色变化?
- azure - Microsoft 评估和规划工具包未发现 Azure VM 上的 MSSQL
- redis - 如何检测 Redis 主/从故障转移?
- angular - `ng-select` 无法在启动时绑定属性
- google-cloud-platform - 如何从 DialogFlow API 创建带有上下文的意图
- redirect - Hybris ?site=electronics 总是重定向到电子网站
- r - 从数据框中选择列列表以转换为子集
- rabbitmq - 如何使用带有 BuiltinExchangeType 主题的 micronaut rabbitmq 客户端
- python - Plotly 多类别 X 轴排序