Open amitrahav opened 8 years ago
I did get access to calendar \o/ here is my code
let moment = require('moment');
Meteor.methods({
'syncProfessionalGoogleCalendar': function (professionalId) {
check(professionalId, String);
let professional = Professionals.findOne({_id: professionalId});
if (professional && professional.owners) {
let userId = professional.owners[0]; // TODO manage multiple owners
if (userId) {
let user = Meteor.users.findOne({_id: userId});
if (user && user.services && user.services.google) {
if (moment(user.services.google.expiresAt).isAfter(moment())) {
Meteor.call('exchangeRefreshToken', userId);
}
let deleteProfessionalEvents = Meteor.bindEnvironment(function() {
Events.remove({professional: professionalId});
return true;
});
// Get all events
GoogleApi.get('calendar/v3/calendars/primary/events', {
user: user,
params: {
'calendarId': 'primary',
'timeMin': new Date().toISOString(),
// 'timeMax': new Date(new Date().setFullYear(new Date().getFullYear() + 1)).toISOString(),
'showDeleted': false,
'singleEvents': true,
'orderBy': 'startTime',
'access_type': 'offline'
}
}, function (error, result) {
if (result && result.items && result.items.length > 0) {
deleteProfessionalEvents();
_.each(result.items, function (event) {
Events.insert({
professional: professionalId,
id: event.id,
startDate: moment(event.start.dateTime).toDate(),
endDate: moment(event.end.dateTime).toDate(),
calendar: 'primary',
title: event.summary,
});
});
return true;
}
if(error){
console.error(error);
}
});
}
}
}
return false;
},
});
also you need the scope to be set client side before the user 'connect with google' like this
// permission to Google calendar offline
Meteor.loginWithGoogle({requestPermissions: ['https://www.googleapis.com/auth/calendar'], forceApprovalPrompt: true, requestOfflineToken: true});
Accounts.ui.config({requestPermissions:{google:['https://www.googleapis.com/auth/calendar']}, forceApprovalPrompt: {google: true}, requestOfflineToken: {google: true}});
Hope it helps
this is my code:
threws this error:
Error: failed [400] { "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Missing end time." } ], "code": 400, "message": "Missing end time." } } (…)
any ideas? can it be related to the json issue?