Как правильно подключиться к Google Spreadsheets API? - PullRequest
0 голосов
/ 27 февраля 2019

Я хочу подключиться к API таблиц Google с помощью Python.

Итак, я делаю:

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope=['https://www.googleapis.com/auth/spreadsheets', 
'https://wwww.googleapis.com/auth/drive']

credentials = ServiceAccountCredentials.from_json_keyfile_name('cred.json', scope)

gc = gspread.authorize(credentials)

wks = gc.open('datatest').Sheet1

print(wks.get_all_records)

Но я получаю эту ошибку

HttpAccessTokenRefreshError: invalid_scope: https://www.googleapis.com/auth/spreadsheets is not a valid audience string.

Как можноЯ использую гугл-аутенти вместо взлома с этими данными?

1 Ответ

0 голосов
/ 27 февраля 2019

вы вводите 4w !!!!

X 'https://wwww.googleapis.com/auth/drive'

O' https://www.googleapis.com/auth/drive'

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('CredentialsFile.json', scope)
ss_app = gspread.authorize(credentials=credentials)  # make sure your Google Sheets API is enabled
sht = ss_app.open('sheet_name_xxxx')  # In your spreadsheet, click the Share button and paste the client email as same as CredentialsFile.json.client_email, and make sure your Google Drive API is enabled
wks = sht.worksheet('worksheet_name_xxxx')
print(wks.acell('A1').value)

надеюсь, что это поможет.

...