0

I believe I'm having the same issue outlined here but that thread never achieved a satisfactory resolution. Essentially I already have a working interface for the Google Sheets API, I added the discoveryDoc and scope for the Slides API to my gapi.client.init() call but when I try to read from my Google presentation with gapi.client.slides.presentations.get() I am met with error code 401 "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential." I have verified that the Slides API is enabled for my API key and I have verified that the presentation I am trying to read from is public, in fact the example presentation provided for the API example page doesn't work either, seemingly my API key is being completely ignored.

gapi.load('client:auth2', () =>
  {
    gapi.client.init({ apiKey: API_KEY,
                       clientId: CLIENT_ID,
                       discoveryDocs: ["https://slides.googleapis.com/$discovery/rest?version=v1", "https://sheets.googleapis.com/$discovery/rest?version=v4"],
                       scope: "https://www.googleapis.com/auth/presentations.readonly https://www.googleapis.com/auth/spreadsheets.readonly"})
    .then(()=>{}, (e)=>{console.log(e)});
  });

enter image description hereenter image description here

EDIT: This is clearly an issue on Google's end. If I use the example documents for the Google Sheets API and the Google Slides API, the id for the public spreadsheet provided for the example documentation is "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms" while the id for the public presentation provided for the Slides API is "1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc".

If I replicate the https GET request being generated through the Sheets API for the provided public example spreadsheet (format is https://sheets.googleapis.com/v4/spreadsheets/[spreadsheetId]?key=[apiKey]) and enter that into my browser with the provided spreadsheet id and my own API key I get the following:

enter image description here

If I replicate the http GET request being generated by the Slides API for the example presentation (format is https://slides.googleapis.com/v1/presentations/[presentationId]?key=[apiKey]) and enter that into my browser with the given presentation id and my API key I get the following:

enter image description here

And since I already verified that I have both the Sheets API and the Sides API enabled for my API Key the issue clearly lies on googles end since the process laid out in their own documentation works for one but not the other. In fact, if I cut the API key in half or scramble it or leave it off altogether i will get an error for the Sheets url that says the API key is not valid, whereas if I do all the same to the Slides url I never get a message about the API key being invalid and still get the same error 401 I've been getting. The Google Slides API blatantly ignores API keys.

Edit 2: This has been reported here over 2 years ago and has been blatantly ignored. Glad a wasted my whole day trying to solve this. Someone should tell google to scrap their API documentation

SemperAmbroscus
  • 1,308
  • 2
  • 12
  • 23
  • Have you checked and confirmed all the scopes needed here? See this post for similar problem. https://stackoverflow.com/questions/53876270/apps-script-execution-api-returns-unauthenticated – Jason E. Jul 19 '21 at 21:48
  • @JasonE. According to the API example "https://www.googleapis.com/auth/presentations" is the only scope required and indeed the analogous scope "https://www.googleapis.com/auth/spreadsheets" is the only scope required for the Sheets API but for whatever reason the latter works while the former doesn't. As it stands the example provided for the Slides API is junk and doesn't work, can't even connect to the provided example presentation – SemperAmbroscus Jul 19 '21 at 23:21
  • @JasonE. please view my edit – SemperAmbroscus Jul 20 '21 at 02:02
  • HI @SemperAmbroscus, It seems you are right. I was also able to replicate your issue and the slides is still problematic. Kindly add on to the linked bug or post another one so that Google knows that there are other users also experiencing this issue. If you are posting a new one, kindly link the previous bug. In the mean time, you might want to consider using OAuth if that works for you. – NightEye Jul 22 '21 at 16:51
  • 1
    @NaziA https://issuetracker.google.com/issues/162477567 This has been reported several times, doesn't seem to be getting looked at. The Google Docs and Google Scripts APIs also don't seem to recognize API keys, the Google Sheets API is the only one I've found that does. I'm in the process of migrating over to using the Google Web App platform since that seems to be the only thing that can reliably access Google cloud documents. It's crazy that for over 2 years several Google APIs have been blatantly not working as specified in the documentation despite being reported several times – SemperAmbroscus Jul 22 '21 at 16:59

0 Answers0