akn*_*ds1 5 javascript google-calendar-api google-api google-api-javascript-client
我正在为浏览器使用Google JavaScript API,但间歇性地失败了,但以下异常:gapi.client.Error: API discovery response missing required fields。是什么原因造成的?
我的用于加载API的代码如下所示,我基本上是将脚本节点注入DOM中以加载API,将整个内容包装在Promise链中以便在就绪时进行处理:
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',
})
})
Run Code Online (Sandbox Code Playgroud)
追溯如下:
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)
Run Code Online (Sandbox Code Playgroud)