python - 尝试更改背景颜色时,Sheets API batchupdate 会出现 TypeError
问题描述
更具体地说,我正在关注谷歌的基本教程,试图为另一个应用程序更改单元格的背景颜色,但现在我正在单独运行它以进行测试。正在运行的代码是
def highlight(sheetId):
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client as gclient, tools
SCOPES = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = gclient.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
servicebot = build('sheets', 'v4', http=creds.authorize(Http()))
reqs = {"requests": [
{
"repeatCell": {
"range": {
"sheetId": sheetId,
"startColumnIndex": 2,
"endColumnIndex": 4,
"startRowIndex": 0,
"endRowIndex": 1,
},
"cell": {
"userEnteredFormat": {
"backgroundColor": {
"red": 1.0,
"green": 0.0,
"blue": 0.0
},
}
},
"fields": "userEnteredFormat(backgroundColor)"
}
}
]}
servicebot.spreadsheets().batchUpdate('19G_4_m-H_jLjXHKxb5Q4PyHSf1Tv9GgbQP-13F95tjQ', body=reqs).execute
highlight(0)
当我运行它时,我得到了错误
Traceback (most recent call last):
File "C:\Users\rexfo\Desktop\autosparring\test.py", line 51, in <module>
highlight(0)
File "C:\Users\rexfo\Desktop\autosparring\test.py", line 49, in highlight
servicebot.spreadsheets().batchUpdate('19G_4_m-H_jLjXHKxb5Q4PyHSf1Tv9GgbQP-13F95tjQ', body=reqs).execute
TypeError: method() takes 1 positional argument but 2 were given
那么我怎么能解决这个问题呢?我做错了什么
解决方案
已经有一段时间了,希望这会有所帮助。我相信执行应该是一种方法。这意味着您需要执行此操作servicebot.spreadsheets().batchUpdate('19G_4_m-H_jLjXHKxb5Q4PyHSf1Tv9GgbQP-13F95tjQ', body=reqs).execute()
才能运行该功能。
:)
推荐阅读
- oracle - 如何在不使用 @ 符号连接数据库的情况下连接数据库。调用 sqlplus UNAME@DBNAME/Password@\\Filelocation
- python - 在 CSV(数字)中查找特定字段值并将其转换为文本值
- haskell - Haskell - 如何使用递归将列表拆分为 n 个长子部分
- python - 如何在 Django 中将字符串转换为调用模型的名称?
- vba - VBA 进行随机计算并确认正确答案
- python - Pandas: how to merge two dataframes on a column by keeping the information of the first one?
- typescript - Angular6 typescript 扩展方法 Observable
- facebook - 如何使用 API v3+ 获取 Facebook 群组帖子作者的数据
- google-chrome - 无法在 Chrome 无头模式下播放 DRM 内容
- c# - MouseEventHandler 的 MouseHook