持续访问Google Calendar API

我如何请求访问用户的日历一次 ,然后查询事件,而不必再次请求访问? 是否有一个访问键,只要它没有被撤销,可以授予连续访问权限?

我目前在运行express + mongodb的nodejs应用程序中使用google-calendar模块。

以下示例显示了进行OAuth请求并redirect回应用的部分代码。 这很好。 我想要的是,只要我有权限,就可以随时查询用户的事件。 这将用于预订应用程序,一旦用户注册他们的公共Google日历,允许其他人看到他们的可用性。

我已经看过Google Calendar API文档,但是我无法弄清楚我需要的持续访问需要什么。

configuration

var GoogleCalendar = require('google-calendar'); var google_calendar = new GoogleCalendar.GoogleCalendar(config.google.clientId, config.google.clientSecret, 'http://localhost:3000/authentication'); 

显示路线

 app.get('/display', function(req, res) { // redirect user to Google Authentication var access_token = req.session.access_token; if(!access_token) { req.session.authReturn = req.url; return res.redirect('/authentication'); } google_calendar.listCalendarList(access_token, function(err, calendarList) { // do something with the calendar events... } ... 

validation路线

 app.all('/authentication', function(req, res){ // Redirect the user to Google's authentication form if(!req.query.code){ google_calendar.getGoogleAuthorizeTokenURL(function(err, redirectUrl) { if(err) return res.send(500,err); return res.redirect(redirectUrl); }); } // Get access_token from the code else { google_calendar.getGoogleAccessToken(req.query, function(err, access_token, refresh_token) { if(err) return res.send(500,err); req.session.access_token = access_token; req.session.refresh_token = refresh_token; return res.redirect(req.session.authReturn); }); } }); 

使用Oauth 2.0脱机访问参数。 详情请见:

https://developers.google.com/accounts/docs/OAuth2WebServer#offline