0

I'm trying to understand how to work with Google Slides API,

I did everything as it was described here.

In "enable Google Slides API" I tried to choose "Desktop app" or "Web Server", but in both ways every time when I try to run quickstart.py file, I get same error:

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://slides.googleapis.com/v1/presentations/1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc?alt=json returned "Request had insufficient authentication scopes.">

This is what i have inside my quickstart.py:

from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

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

# The ID of a sample presentation.
PRESENTATION_ID = '1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc'

def main():
    """Shows basic usage of the Slides API.
    Prints the number of slides and elments in a sample presentation.
    """
    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)

    service = build('slides', 'v1', credentials=creds)

    # Call the Slides API
    presentation = service.presentations().get(
        presentationId=PRESENTATION_ID).execute()
    slides = presentation.get('slides')

    print('The presentation contains {} slides:'.format(len(slides)))
    for i, slide in enumerate(slides):
        print('- Slide #{} contains {} elements.'.format(
            i + 1, len(slide.get('pageElements'))))


if __name__ == '__main__':
    main()

Updated:

Whole error msg looks like this:

Traceback (most recent call last):
  File "/Users/A/PycharmProjects/PyProjects/quickstart.py", line 54, in <module>
    main()
  File "/Users/A/PycharmProjects/PyProjects/quickstart.py", line 44, in main
    presentationId=PRESENTATION_ID).execute()
  File "/Users/A/PycharmProjects/PyProjects/venv/lib/python3.7/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Users/A/PycharmProjects/PyProjects/venv/lib/python3.7/site-packages/googleapiclient/http.py", line 907, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://slides.googleapis.com/v1/presentations/1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc?alt=json returned "Request had insufficient authentication scopes.">
Kos
  • 4,890
  • 9
  • 38
  • 42
Antonych
  • 79
  • 7
  • 1
    Does this answer your question? [Google spreadsheet api Request had insufficient authentication scopes](https://stackoverflow.com/questions/38534801/google-spreadsheet-api-request-had-insufficient-authentication-scopes) – D. Foley Jul 09 '20 at 06:23
  • thanks for reply, but nope, this didn't answer my question :( – Antonych Jul 09 '20 at 06:34
  • Although I'm not sure whether this is the direct solution, for example, when `token.pickle` is deleted and reauthorize the scope and run the script again, what result will you get? – Tanaike Jul 09 '20 at 06:39
  • Its says: # 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 my understanding is correct, token.pickle will be created after authorization flow completes. But it didn't, so i didn't even have this file yet. – Antonych Jul 09 '20 at 06:45
  • What line number is shown when that error is reported? I just followed the quickstart example and it's working for me. Curious as to why it fails for you.. – D. Foley Jul 09 '20 at 07:05
  • @D. Foley please check the update of the post. – Antonych Jul 09 '20 at 07:39
  • Can you please log into the developer console and double check that the slides API is enabled? I don't think there is anything wrong with the code per se, I think there is a misconfiguration on your account. – D. Foley Jul 09 '20 at 08:12
  • Are you using the `credentials.json` provided by the *quickstart* page or one from a GCP project? – Raserhin Jul 09 '20 at 10:15

1 Answers1

0

Hello I have stumbled upon the same issue it is easily solvable, you just have to approve it manually.

https://developers.google.com/people/quickstart/python#step_1_turn_on_the

So press the Enable the People API button and it should open a new window where you have to login manually first time for the approval hope it helps.