Ich versuche, aus einer persönlichen Tabelle mit der Google API (v4) für Tabellen zu lesen.
Ich habe den Code aus dem Beispiel kopiert, das google bereitstellt, während ich die Tabellenkalkulations-ID, den Bereichsnamen und den Bereich ändere.
Egal was ich mache (mache die Tabelle öffentlich) Ich bekomme einen HttpError: 404 Angeforderte Entität wurde nicht gefunden.
Zugriff auf eine Tabelle in Google Tabellen mit python3
Mein Code:
import httplib2
import os
from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly',
'https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.readonly']
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'python'
def get_credentials():
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'sheets.googleapis.com-python.json')
store = Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
credentials = tools.run_flow(flow, store, None)
return credentials
def main():
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
discoveryUrl = ('https://sheets.googleapis.com/$discovery/rest?'
'version=v4')
service = discovery.build('sheets', 'v4', http = http,
discoveryServiceUrl = discoveryUrl)
spreadsheetId = 'ID'
rangeName = 'RANGE'
result = service.spreadsheets().values().get(
spreadsheetId = spreadsheetId, range = rangeName).execute()
Werfen Sie einen Blick auf die api doc für das Erhalten der Tabelle hier: https://developers.google.com/resources/ api-libraries/documentation/sheets/v4/python/latest/sheets_v4.spreadsheets.html # get –
Ich fürchte, ich war schon dort ... keine Hilfe, warum das Blatt nicht verfügbar ist –
Haben Sie die ID dreifach überprüft ? auf sheets.google.com ist es nach dem/d/in der URL –