Не очень опыт работы с аутентификацией API, но я не могу понять, как читать общий ресурс Google Sheet со мной из Python.
Я пробовал:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('/Users/alexiseggermont/Downloads/Accountable-7b29dac08324.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open("mysheet").sheet1
Это дает мне ImportError: cannot import name 'opentype'
в строке 2.
Я тогда попробовал:
import oauth2client.client, oauth2client.file, oauth2client.tools
import gspread
flow = oauth2client.client.OAuth2WebServerFlow(client_id, client_secret, 'https://spreadsheets.google.com/feeds')
storage = oauth2client.file.Storage('credentials.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
import argparse
flags = argparse.ArgumentParser(parents=[oauth2client.tools.argparser]).parse_args([])
credentials = oauth2client.tools.run_flow(flow, storage, flags)
gc = gspread.authorize(credentials)
# when this cell is run, your browser will take you to a Google authorization page.
# this authorization is complete, the credentials will be cached in a file named credentials.dat
Откроется окно с вопросом, хочу ли я предоставить моему приложению доступ к моим листам, и я нажимаю «да». Но тогда sheet = gc.open("mysheet").sheet1
выдает ошибку разрешения:
APIError: {
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}
Единственное предложение, которое я нахожу для решения этой ошибки, - это изменение переменной 'scope', но в этом коде не используется переменная scope, поэтому я в замешательстве.