使用Google Sheets API,我可以使用get方法从表中获取数据,但是append方法给出了一个错误

from googleapiclient.discovery import build
from google.oauth2 import service_account
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
SERVICE_accOUNT_FILE = 'keys.json'
credentials=None
credentials = service_account.Credentials.from_service_account_file(
        SERVICE_accOUNT_FILE,scopes=SCOPES)
SAMPLE_SPREADSHEET_ID= '1nRVonS_Akp14vlzAiDlyH6mDRetS3bB62w1cfWZi***'
sheet = service.spreadsheets()

#GET
result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,range="Sayfa1!A1:A2").execute()
print(result)
aoa=["1"]
#APPEND
request = sheet.values().append(spreadsheetId=SAMPLE_SPREADSHEET_ID,range="A1",valueInputOption="USER_ENTERED",insertDataOption="INSERT_ROWS",body={"values":aoa}).execute()

当我运行此代码时,出现此错误:

C:\Python39\python.exe C:/Users/seher/PycharmProjects/temizbirsayfa/main.py {'range': 'Sayfa1!A1:A2','majorDimension': 'ROWS','values': [['1'],['5']]} 回溯(最近一次通话):文件 “C:\Users\seher\PycharmProjects\temizbirsayfa\main.py”,第 23 行,在 request = sheet.values().append(spreadsheetId=SAMPLE_SPREADSHEET_ID,body={"values":aoa}).execute() 文件 “C:\Python39\lib\site-packages\googleapiclient_helpers.py”,第 134 行, 在 positional_wrapper 中 返回wrapped(*args,**kwargs) File "C:\Python39\lib\site-packages\googleapiclient\http.py",line 915,in 执行 请求时引发 HttpError(resp,content,uri=self.uri) googleapiclient.errors.HttpError: https://sheets.googleapis.com/v4/spreadsheets/1nRVonS_Akp14vlzAiDlyH6mDRetS3bB62w1cfWZi***/values/A1:append?valueInputOption=USER_ENTERED&insertDataOption=INSERT_ROWS&alt=json 返回“调用者没有权限”。详细信息:“来电者 没有权限">

进程以退出代码 1 结束

它说我没有权限,但我有权限,因为我可以从工作表中获取数据。那么问题是什么?我该如何解决?

anothermimi 回答:使用Google Sheets API,我可以使用get方法从表中获取数据,但是append方法给出了一个错误

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1013281.html

大家都在问