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:
进程以退出代码 1 结束
它说我没有权限,但我有权限,因为我可以从工作表中获取数据。那么问题是什么?我该如何解决?