gpt4 book ai didi

python - 列出使用 gspread 创建的谷歌电子表格

转载 作者:行者123 更新时间:2023-12-01 13:38:08 24 4
gpt4 key购买 nike

我使用 gspread 创建了一些电子表格。

因为它们是使用 Google 服务 key 帐户创建的,所以我不知道如何访问它们。

如何查看使用特定服务 key 创建的所有电子表格?

https://github.com/burnash/gspread

最佳答案

终于找到答案了。

直接查看 gspread 代码后,我发现了这个:https://github.com/burnash/gspread/blob/addd4940bf7e4f87aae598920facae2155e555b6/gspread/client.py#L151

所以这是可行的:

from oauth2client.service_account import ServiceAccountCredentials
import gspread
from gspread.ns import _ns

# If modifying these scopes, delete your previously saved credentials
# at ~/.credentials/sheets.googleapis.com-python-quickstart.json
SCOPES = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Google Sheets API Python'


def get_credentials():
"""Gets valid user credentials from storage.

If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.

Returns:
Credentials, the obtained credential.
"""

return ServiceAccountCredentials.from_json_keyfile_name(CLIENT_SECRET_FILE, SCOPES)

credentials = get_credentials()
gc = gspread.authorize(credentials)
feed = gc.get_spreadsheets_feed()

for elem in feed.findall(_ns('entry')):
elem_title = elem.find(_ns('title')).text
print(elem_title)

关于python - 列出使用 gspread 创建的谷歌电子表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42413586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com