【发布时间】:2019-10-28 03:59:23
【问题描述】:
问候我的开发者伙伴 我正在开发一个项目,客户需要将 Google 日历与该项目连接起来。 我正在使用 GAPI 将 Google 日历与我的应用程序连接起来。 这是我正在做的事情:
第 1 步:
let config = {
apiKey: [API_KEY],
clientId: [CLIENT_ID],
access_type: 'offline',
discoveryDocs: ['https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest'],
scope: 'https://www.googleapis.com/auth/calendar.events'
}
gapi.load('client:auth2', () => {
gapi.client.init(config).then(() => {
gapi.auth2.getAuthInstance().isSignedIn.listen(true);
});
});
第 2 步:
Promise.resolve(gapi.auth2.getAuthInstance().signIn()).then(response => {
store access_token, id_token, login_hint
}).then(() => {
run_different_axios_requests_to_google_calendar();
});
或者如果我已经拥有访问令牌:
run_different_axios_requests_to_google_calendar();
到目前为止它运行完美!
访问令牌过期时会出现问题,并阅读文档,我发现如果您运行 gapi.auth2.getAuthInstance(). grantOfflineAccess() 而不是 gapi.auth2.getAuthInstance().signIn() 您会得到 refresh_token 以及 access_token、id_token、login_hint,但是我没有得到回应,事实上我的承诺表明This app isn't verified,并且我需要在 access_token 过期时刷新令牌,以便我可以获得新的令牌,而不必要求用户再次登录(通过承诺)。我不确定我在这里做错了什么!任何帮助表示赞赏!
【问题讨论】:
标签: javascript google-calendar-api google-api-js-client