ユーザーのカレンダーへのアクセスを一度リクエストしてから、再度アクセスをリクエストせずにイベントをクエリするにはどうすればよいですか?取り消されない限り、継続的なアクセスを許可できるアクセスキーはありますか?
私は現在、express + mongodbを実行しているnodejsアプリでgoogle-calendarモジュールを使用しています。
以下の例は、OAuthリクエストを作成してアプリにリダイレクトするための部分的なコードを示しています。これはうまくいきます。ただし、アクセスできるようになったら、いつでもユーザーのイベントを照会できるようにしたいのです。これは予約アプリで使用され、ユーザーが公開されているGoogleカレンダーを登録すると、他のユーザーが自分の空き状況を確認できるようになります。
Google Calendar APIのドキュメントを見ましたが、必要な継続的なアクセスに何が必要かわかりません。
構成:
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...
}
...
ルートを認証する:
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);
});
}
});