Tin*_*ger 9 javascript typescript google-oauth vue.js
我正在尝试在我的 Vue / Quasar / TypeScript 应用程序中使用新的 Google Identity Services JavaScript SDK 授权一些 Google API。
根据文档,我已在文件的标头中加载了 Google 3P 授权 JavaScript 库,index.template.HTML如下所示:
<script src="https://accounts.google.com/gsi/client" onload="console.log('TODO: add onload function')">
</script>
Run Code Online (Sandbox Code Playgroud)
现在在 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>
Run Code Online (Sandbox Code Playgroud)
但我在“google”上收到 TypeScript 错误,内容如下:Cannot find name 'google'. ts(2304)
也许是因为我缺少 Google Identity Services JavaScript SDK 的类型?如果是这样,在哪里可以找到它们?
或者问题可能是别的什么?
| 归档时间: |
|
| 查看次数: |
3148 次 |
| 最近记录: |