Google Sheets API-Python-创建工作表

问题描述 投票:0回答:1

我是API的新手,我正在尝试使用python创建一个Google工作表。我能够创建Google工作表,但无法查看/编辑(访问问题)。我在API中使用服务帐户。请帮助我修改代码以访问创建的工作表。

这是我用来创建一个的示例代码。

service = discovery.build('sheets', 'v4', credentials=credentials)

spreadsheet_body = {
}

request = service.spreadsheets().create(body=spreadsheet_body)
response = request.execute()
google-sheets-api google-api-python-client
1个回答
0
投票
  • 最有可能您将工作表创建为服务帐户-默认情况下,在其云端硬盘上,这就是为什么访问它时遇到问题的原因。
  • 如果要在驱动器上创建工作表,则需要使用模拟功能:

  • enabling domain-wide delegation之后,您需要以自己的身份模拟服务帐户。

  • 在python中,您可以通过在credentials = credentials.create_delegated(user_email)时指定instantiating the service object来做到这一点。

© www.soinside.com 2019 - 2024. All rights reserved.