-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
calendar json issue #38
Comments
I did get access to calendar \o/ 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
The text was updated successfully, but these errors were encountered: