我正在尝试在我的 Vue / Quasar / TypeScript 应用中使用新的 Google Identity Services JavaScript SDK 授权某些 Google API。
根据文档,我已在 index.template.HTML
文件的标头中加载了 Google 3P 授权 JavaScript 库,如下所示:
<script src="https://accounts.google.com/gsi/client" onload="console.log('TODO: add onload function')"> </script>
现在在 Vue 组件中我有这个:
<template> <v-btn class="q-ma-md" design="alpha" label="Connect Google Calendar" @click="handleGoogleCalendarConnect" /> </template> <script setup lang="ts"> import VBtn from 'src/components/VBtn.vue'; const client = google.accounts.oauth2.initCodeClient({ // <-- TypeScript Error Here client_id: 'MY_CLIENT_API_KEY_GOES_HERE', scope: 'https://www.googleapis.com/auth/calendar.readonly', ux_mode: 'popup', callback: (response: any) => { const xhr = new XMLHttpRequest(); xhr.open('POST', code_receiver_uri, true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // Set custom header for CRSF xhr.setRequestHeader('X-Requested-With', 'XmlHttpRequest'); xhr.onload = function () { console.log('Auth code response: ' + xhr.responseText); }; xhr.send('code=' + code); }, }); const handleGoogleCalendarConnect = () => { client.requestCode(); }; </script>
但是我在“google”上收到 TypeScript 错误,内容为:Cannot find name 'google'。 ts(2304)
也许是因为我缺少 Google Identity Services JavaScript SDK 的类型?如果是这样,在哪里可以找到它们?
或者问题可能是别的什么?