D
D
DanTheMan2017-05-04 20:27:59
Google
DanTheMan, 2017-05-04 20:27:59

The OAuth client was not found.?

Hello!
I am trying to start reading google spreadsheet using python.
But when I run the file from the terminal, I get this error.
What to do?
5d85450fe6844300b86ee5362aa4051f.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elvis, 2017-05-05
@Dr_Elvis

This is how I read the GD tables (there may be too much in imports, I just deleted my code):

from __future__ import print_function
import httplib2
import os
import configparser as cfg
import requests
from apiclient import discovery
import oauth2client
from oauth2client import client
from oauth2client import tools

try:
  import argparse
  flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
  flags = None

SCOPES = 'https://www.googleapis.com/auth/spreadsheets'
CLIENT_SECRET_FILE = 'client_id.json'
APPLICATION_NAME = 'APPLICATION_NAME'
config = cfg.ConfigParser()
config.read('Config.ini', encoding='utf_8') # чтение конфиг файла
GDURL = config['DEFAULT']['GDURL'] # ссылка на ГД
RangeName = config['DEFAULT']['RangeName'] # Название листа в ГД


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-quickstart.json')
  store = oauth2client.file.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
    if flags:
      credentials = tools.run_flow(flow, store, flags)
    else: # Нужно для Python 2.6
      credentials = tools.run(flow, store)
    print('Storing credentials to ' + credential_path)
  return credentials


def main():
  requests.packages.urllib3.disable_warnings()
  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 = str(GDURL).split('/')[5]
  result = service.spreadsheets().values().get(
    spreadsheetId=spreadsheetId, range=RangeName).execute()
  values = result.get('values', [])

  if not values:
    print('Нет данных')
  else:
    # здесь мой код


if __name__ == '__main__':
  main()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question