I'm using the Google JavaScript API for the browser, and intermittently it fails with the following exception: gapi.client.Error: API discovery response missing required fields
. What might be causing this?
My code for loading the API looks as follows, I'm basically injecting a script node into the DOM in order to load the API, wrapping the whole thing in a Promise chain in order to handle when it's ready:
new Promise((resolve, reject) => {
const script = document.createElement('script')
script.onload = resolve
script.onerror = reject
document.currentScript.parentNode.insertBefore(script, document.currentScript)
script.src = 'https://apis.google.com/js/api.js'
})
.then(() => {
return new Promise((resolve) => {
gapi.load('client:auth2', resolve)
})
})
.then(() => {
return gapi.client.init({
discoveryDocs: ['https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest',],
apiKey: initialState.googleApiKey,
clientId: initialState.oauthClientId,
scope: 'email profile https://www.googleapis.com/auth/calendar',
})
})
The traceback looks as follows:
gapi.client.Error: API discovery response missing required fields.
at new wY (https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en_US.nyHIlPOzvxo.O/m=auth2,client/rt=j/sv=1/d=1/ed=1/am=AQ/rs=AGLTcCNWHYGSUbRcGfoOSnVtpSAoqp5S-Q/cb=gapi.loaded_0:653:491)
at f (https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en_US.nyHIlPOzvxo.O/m=auth2,client/rt=j/sv=1/d=1/ed=1/am=AQ/rs=AGLTcCNWHYGSUbRcGfoOSnVtpSAoqp5S-Q/cb=gapi.loaded_0:696:457)
at h.o0 (https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en_US.nyHIlPOzvxo.O/m=auth2,client/rt=j/sv=1/d=1/ed=1/am=AQ/rs=AGLTcCNWHYGSUbRcGfoOSnVtpSAoqp5S-Q/cb=gapi.loaded_0:79:171)
at xs (https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en_US.nyHIlPOzvxo.O/m=auth2,client/rt=j/sv=1/d=1/ed=1/am=AQ/rs=AGLTcCNWHYGSUbRcGfoOSnVtpSAoqp5S-Q/cb=gapi.loaded_0:82:245)
at Wq (https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en_US.nyHIlPOzvxo.O/m=auth2,client/rt=j/sv=1/d=1/ed=1/am=AQ/rs=AGLTcCNWHYGSUbRcGfoOSnVtpSAoqp5S-Q/cb=gapi.loaded_0:82:96)
at null._.C.uea (https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en_US.nyHIlPOzvxo.O/m=auth2,client/rt=j/sv=1/d=1/ed=1/am=AQ/rs=AGLTcCNWHYGSUbRcGfoOSnVtpSAoqp5S-Q/cb=gapi.loaded_0:81:242)
at Ap (https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en_US.nyHIlPOzvxo.O/m=auth2,client/rt=j/sv=1/d=1/ed=1/am=AQ/rs=AGLTcCNWHYGSUbRcGfoOSnVtpSAoqp5S-Q/cb=gapi.loaded_0:75:300)