Недостаточно данных о Google API - PullRequest
1 голос
/ 24 января 2020

Я пытаюсь понять, что это за ошибка:

  File "C:\...\googleapiclient\http.py", line 856, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/19XYXTA2xER982xIHnDqH0cOtjBtSZtgC?alt=media returned "Insufficient Permission: Request had insufficient authentication scopes.">

Что означает «Недостаточное разрешение: у запроса недостаточно областей проверки подлинности». значит?

Ниже приведен весь код: учетные данные. json и client_secrets. json оба присутствуют в моем каталоге.

from __future__ import print_function
import pickle
import os.path
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
import os
g_login = GoogleAuth()
g_login.LocalWebserverAuth()  # This sucker might break [NK]
drive = GoogleDrive(g_login)
#end of tempCodeForEaseOfUse [NK]

# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/documents'] # https://www.googleapis.com/auth/drive.metadata.readonly https://www.googleapis.com/auth/documents.readonly']

# The ID and range of a sample spreadsheet.
SAMPLE_SPREADSHEET_ID = '1eb0DIJ7QglHqCrvIW94MUbMvFdbGKGXBSwaH49ILCvQ/edit?usp=sharing'
SAMPLE_RANGE_NAME = 'Class Data!A2:E'

creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.pickle'):
    with open('token.pickle', 'rb') as token:
        creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
        creds.refresh(Request())
    else:
        flow = InstalledAppFlow.from_client_secrets_file(
            'credentials.json', SCOPES)
        creds = flow.run_local_server(port=0)
    # Save the credentials for the next run
    with open('token.pickle', 'wb') as token:
        pickle.dump(creds, token)


# TODO: fileID extracted manually, must automate [NK]
fileId = '19XYXTA2xER982xIHnDqH0cOtjBtSZtgC/view?usp=sharing'  # Please set the file ID of text file. [StackTanaike]

sheets = build('sheets', 'v4', credentials=creds)
drive = build('drive', 'v3', credentials=creds)

# Retrieve data from Google Drive and parse data as an array. [StackTanaike]
data = drive.files().get_media(fileId=fileId).execute()

1 Ответ

1 голос
/ 24 января 2020

Ваши области установлены неправильно. Замените ваш SCOPES = ['https:// ... следующим:

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

...