python - google sheet API batchUpdate在python中返回错误
问题描述
我正在尝试使用 python 3.6 中的以下代码将值从一张表粘贴到另一张表中。
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
SCOPES = 'https://www.googleapis.com/auth/spreadsheets'
store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('sheets', 'v4', http=creds.authorize(Http()))
spreadsheet_id = 'XXXXXXXXXXXXXXXXX'
request_body = {
'requests': [{
'copyPaste':{
"source": {
"sheetId": XXXXXX,
"startRowIndex": 0,
"endRowIndex": 1000,
"startColumnIndex": 0,
"endColumnIndex": 5
},
"destination": {
"sheetId": XXXXXXXX,
"startRowIndex": 0,
"endRowIndex": 1000,
"startColumnIndex": 0,
"endColumnIndex": 5
},
"pasteOrientation": "NORMAL",
"pasteType": "PASTE_VALUES"
}
}]
}
request = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id, body=request_body)
response = request.execute()
pprint(response)
但是我不断收到以下错误,我尝试添加更多范围 URL,但无济于事。
---------------------------------------------------------------------------
---> 41 response = request.execute()
HttpError: <HttpError 403 when requesting https://sheets.googleapis.com/v4/spreadsheets/xxxxxxxxxxxxxxxxxx?alt=json returned "Request had insufficient authentication scopes.">
解决方案
推荐阅读
- php - 如何正确连接具有多对一关系的表
- javascript - 是否可以通过解构从数组创建对象?
- tensorflow - Keras 中的动态激活函数
- .net - .Net Core 在 SQL 连接中是否比 .Net Framework 慢得多?
- php - 判断数组中的空值并获取key数组
- asp.net-mvc - 登录时如何在我的应用程序中获取最后一个工作页面
- html - 在 reactjs 中通过两个输入 type="range" 创建一个滑块
- arrays - 如何在 Actionscript 3.0 中获取数组的所有排列?
- python - 根据创建日期对一个列表中的两个模型进行排序
- php - 来自新输入和数据库值的 PHP 验证