我试图在我的Vue / Quasar / TypeScript应用程序中使用新的Google服务TypeScript SDK来授权一些Google。
作为按照医生的说法,我已经将Google3P授权JavaScript库加载到我的index.template.HTML文件的头中,如下所示:
<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)
也许是因为我错过了谷歌身份服务JavaScript SDK的类型?如果是的话,哪里可以找到他们?
或者问题是别的什么?
发布于 2022-05-14 10:41:48
找到正确的类型包:
npm i @types/google.accounts
这将消除错误。
https://stackoverflow.com/questions/72238650
复制相似问题