列出使用 gspread 创建的 google 电子表格

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

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

由于它们是使用谷歌服务关键帐户创建的,我不知道如何访问它们。

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

https://github.com/burnash/gspread

python gspread
2个回答
3
投票

终于找到答案了。

直接查看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)

0
投票

我尝试了列表理解,但仍然没有解决问题。我将其作为第二个参数传递给连接。

alltogether= ','.join([gendata 中的项目的 str(item)])

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