Cannot read properties of undefined (reading 'getActiveSpreadsheet')
时间: 2023-11-21 22:58:50 浏览: 28
这个错误通常是因为未正确引用Google Sheets API导致的。请确保已经正确引用了Google Sheets API并且已经授权访问。以下是一个使用Google Sheets API读取数据的Python示例代码:
```python
import gspread
from oauth2client.service_account import ServiceAccountCredentials
# 认证
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)
# 打开表格
sheet = client.open('表格名称').sheet1
# 读取数据
data = sheet.get_all_records()
# 输出数据
print(data)
```
请注意,上述代码中的“client_secret.json”是您的Google API凭据文件的名称。您需要将其替换为您自己的凭据文件名,并将其放置在与Python文件相同的目录中。此外,您还需要将“表格名称”替换为您要读取的实际表格的名称。