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)});
});
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:
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:
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