Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 谷歌日历API-类型脚本类型_Typescript_Api_Calendar_Google Calendar Api - Fatal编程技术网

Typescript 谷歌日历API-类型脚本类型

Typescript 谷歌日历API-类型脚本类型,typescript,api,calendar,google-calendar-api,Typescript,Api,Calendar,Google Calendar Api,有人知道node.js(或浏览器)的google日历API(npm googleapis pkg)是否有可用于typescript的类型吗。 允许在节点或角度中使用强类型方法 我找不到@types/googleapis npm包。 医生里也没有 欢迎任何建议 提前谢谢 -- 文档说它是本机支持的,不需要单独的包。 但是,当我尝试时,正如文件中所述 import { google, calendar_v3 } from 'googleapis'; Typescript告诉我: [ts]模

有人知道node.js(或浏览器)的google日历API(npm googleapis pkg)是否有可用于typescript的类型吗。 允许在节点或角度中使用强类型方法

我找不到@types/googleapis npm包。 医生里也没有

欢迎任何建议

提前谢谢

-- 文档说它是本机支持的,不需要单独的包。 但是,当我尝试时,正如文件中所述

    import { google, calendar_v3 } from 'googleapis';
Typescript告诉我: [ts]模块“/home/me/myProject/functions/node_modules/googleapis/build/src/index”没有导出的成员“calendar_v3”。[2305]

当我查看googleapis/build/src/index.d.ts时,我看到了googleapis,它指向所有API所在的../API,带有一个包含名称空间的v3.d.ts文件

    * @namespace calendar
    * @type {Function}
    * @version v3
    * @variation v3
所以,很明显,它在那里,但我错过了一些东西。。。但是什么呢? 如何在typescript中使用此库? 我们欢迎举个例子

Philippe

尝试以下内容,我尝试了本教程将Google API集成到我的angular应用程序中。它不是
@types/googleapis
,而是
@types/gapi

npm install --save @types/gapi
npm install --save @types/gapi.auth2
npm install --save @types/gapi.client.drive

您将调用
gapi.client.drive
而不是
gapi.client.calendar
,您完全可以将此库与TypeScript一起使用。这是用打字机写的!以下是一个基本示例:

import{google}来自'googleapis';
const calendar=google.calendar('v3');
这是获取API特定小节引用的正确方法:)


希望这有帮助

@justin beckwith的答案是正确的,但检索类型也值得一个例子:

import { calendar_v3, google } from 'googleapis';
import { OAuth2Client, Credentials } from 'google-auth-library';
import Calendar = calendar_v3.Calendar;
import Schema$Event = calendar_v3.Schema$Event;

const auth: OAuth2Client = new google.auth.OAuth2(...);
const calendar: Calendar = google.calendar({ version: 'v3', auth });
const schemaEvent: Schema$Event = (await calendar.events.get({ calendarId, eventId })).data;

谢谢你,傻瓜。根据我正在寻找node.js上的服务器实现。你的答案仍然很有趣。卓别林,你能做到吗?如果是这样的话,你能给我们放一个Codepen或JSFiddle之类的东西吗?谢谢我不建议在node.js上使用客户端,反之亦然。但是,如果客户端(浏览器)能够在不久的将来达成共识,让大多数东西在ES6/7上运行,那就太好了。我这里的问题是,google.calendar()不接受JWT类型的身份验证,这是使用服务帐户时需要的。我这里的问题是google.calendar()不接受JWT类型的身份验证,这是使用服务帐户时需要的。