Н̶а̶п̶и̶с̶а̶л̶ Скопировал код:
import httplib2
import os
from googleapiclient import discovery
from google.oauth2 import service_account
try:
scopes = ["https://www.googleapis.com/auth/spreadsheets",]
secret_file = os.path.join(os.getcwd(), "client_secret.json")
spreadsheet_id = "..."
range_name = "Sheet1!B3"
credentials = service_account.Credentials.from_service_account_file(secret_file, scopes=scopes)
service = discovery.build("sheets", "v4", credentials=credentials)
values=service.spreadsheets().values().get(spreadsheetId=spreadsheet_id,range=range_name,).execute()
print(values.get('values'))
except OSError as e:
print(e)
Когда запускаю, выдает вот это:
Traceback (most recent call last):
File "main.py", line 17, in <module>
values=service.spreadsheets().values().get(spreadsheetId=spreadsheet_id,range=range_name,).execute()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/googleapiclient/http.py", line 920, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/.../values/Sheet1%21B3?alt=json returned "Unable to parse range: Sheet1!B3". Details: "Unable to parse range: Sheet1!B3">
Когда сам перехожу по ссылке пишет:
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"status": "PERMISSION_DENIED"
}
}
Как исправить???