我正在尝试通过 python 编辑 Google Sheets 文件。我正在使用 Google API,但它们都在“后端”进行了更改(例如 openpyxl)。我想在浏览器上看到变化。对我来说,这就像在无头与“正常”之间运行 selenium。
我从 GoogleAPIclient 尝试了这段代码:
from googleapiclient.discovery import build
from google.oauth2 import service_account
SERVICE_accOUNT_FILE = 'keys.json'
SCOPES = ['https://www.googleapis.com/auth/spreadsheets','https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
creds = None
creds = service_account.Credentials.from_service_account_file(
SERVICE_accOUNT_FILE,scopes=SCOPES)
service = build('sheets','v4',credentials=creds)
sheet = service.spreadsheets()
以及来自 gspread 的代码
import gspread
SERVICE_accOUNT_FILE = 'keys.json'
SCOPES = ['https://www.googleapis.com/auth/spreadsheets',scopes=SCOPES)
client = gspread.authorize(creds) #from another website
sheet = client.open(file_id) #from another website