Hi,
In my application(in nodeJs) I am using goolge calendar to list out all events. I am using following code.
var GoogleCalendar = require('google-calendar');
var notLoggedIn = require('./middleware/not_logged_in');
var google_calendar = new GoogleCalendar.GoogleCalendar(
'client-id',
'client-key',
'
http://localhost:3000/new');
module.exports = function(app) {
app.all('/new', notLoggedIn, function(req, res){
if(!req.query.code){
//Redirect the user to Google's authentication form
google_calendar.getGoogleAuthorizeTokenURL(function(err, redirecUrl) {
if(err) return res.send(500,err);
return res.redirect(redirecUrl);
});
}
else{
//Get access_token from the code
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('/calendar_event/list');
});
}
});
app.get('/calendar_event/list', notLoggedIn, function(req, res, next){
var access_token = req.session.access_token;
users = req.session.user;
if(!access_token){
res.redirect('/new');
}
else{
//Events.list
var z = 0;
google_calendar.listEvent(access_token, '
calender.id', function(err, events) {
if(err)console.log(err);
events = events.items;
res.render('calendar/events', {title: 'Event List', events: events, users: users});
});
}
});
};
The problem it requires me login to access my calendar. Is there any way to avoid the login winow and it will autometically get access by the application.
Please help.
Thanks
Swarup