首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在GoogleSheets接口v4中使用findReplace函数需要什么作用域?

在GoogleSheets接口v4中使用findReplace函数需要什么作用域?
EN

Stack Overflow用户
提问于 2019-06-11 05:00:11
回答 1查看 286关注 0票数 1

我想在Google Sheets APIv4中使用findReplace请求。我按照Google quickstart guide for the Sheets API in Python中的定义设置了我的作用域和请求,并确认API可以与我的电子表格对话。

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#FindReplaceRequest

代码语言:javascript
复制
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
SHEET_ID = myspreadsheetid
creds = None
store = file.Storage('sheets_token.json')

if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
        creds.refresh(Request())
    else:
        flow = client.flow_from_clientsecrets('client_2_https.json', SCOPES)
        creds = tools.run_flow(flow, store, http=Http(disable_ssl_certificate_validation=True))
    with open('sheets_token.pickle', 'wb') as token:
        pickle.dump(creds, token)

adminService = build('sheets', 'v4', http=creds.authorize(Http(disable_ssl_certificate_validation=True)))

def findreplace_request(find, replacement):
  findreplace_request = {}
  findreplace_request['find'] = find
  findreplace_request['replacement'] = replacement
  findreplace_request['matchCase'] = True
  findreplace_request['matchEntireCell'] = True
  findreplace_request['searchByRegex'] = False
  findreplace_request['includeFormulas'] = False
  findreplace_request['sheetId'] = mysheetid
  allSheets = False
  request = {}
  request['findReplace'] = findreplace_request
  return request


body = {}
body.setdefault('requests',[]).append(findreplace_request('@mydate@','TODAY'))

response = adminService.spreadsheets().batchUpdate(spreadsheetId=SHEET_ID, body=my_request).execute()   

我清楚地设置了一个从Google Sheets读写的作用域,但是我不明白为什么我得到一个错误,说没有设置作用域。

代码语言:javascript
复制
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\wnh659\AppData\Local\Continuum\anaconda3\lib\site-packages\googleapiclient\_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "C:\Users\wnh659\AppData\Local\Continuum\anaconda3\lib\site-packages\googleapiclient\http.py", line 851, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/1Sx0CJJo-b6Z6JUaQEQ6cJ3Yxtjv3z9BtHN9EHl0-0jU:batchUpdate?alt=json return
ed "Invalid requests[0].findReplace: scope not set.">
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56533468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档