Hi experts,
I want to add google calendar for event same as google contact in my mvc application
my need is i have a textbox for date and a button for add this date to google calender. and i have no idea how i implement this. if any one has the code for the same send me.
Thanks
What I have tried:
var CLIENT_ID = 'myclientid';
var SCOPES = ["https://www.googleapis.com/auth/calendar"];
function checkAuth() {
alert('aa');
gapi.auth.authorize(
{
'client_id': CLIENT_ID,
'scope': SCOPES,
'immediate': true
}, handleAuthResult);
}
$("#GotoAuthSubLink").click(function () {
handleAuthClickResult(event)
});
function handleAuthResult(authResult) {
alert('bb');
var authorizeDiv = document.getElementById('GotoAuthSubLink');
if (authResult.error) {
} else {
authorizeDiv.style.display = 'inline';
}
}
function handleAuthClickResult(authResult) {
alert('yes');
var authorizeDiv = document.getElementById('GotoAuthSubLink');
if (authResult && !authResult.error) {
loadCalendarApi();
} else {
authorizeDiv.style.display = 'inline';
appendPre('Please try later!');
}
}
function handleAuthClick(event) {
gapi.auth.authorize(
{client_id: CLIENT_ID, scope: SCOPES, immediate: false},
handleAuthClickResult);
return false;
}
function loadCalendarApi() {
gapi.client.load('calendar', 'v3', addEventToGoogleCalendar);
}
function appendPre(message) {
document.getElementById('calendarOutput').innerHTML = message;
alert(message);
}
function addEventToGoogleCalendar() {
var date = $("#datepicker3").val();
alert(date);
if (date.length < 6) {
appendPre("Select a date");
} else {
var parts = date.split('/');
var startDate = new Date(parts[2], parts[1] - 1, parts[0]);
var endDate = new Date(startDate.getTime() + (12 * 1000 * 60 * 60));
var eventAddress = $("#lblUserDetails").val();
var eventName = $("#lblOwnerDetails").val();
var event = {
'summary': eventName,
'location': eventAddress,
'description': 'Connect with ' + eventName + ' at ' + eventAddress,
'start': {
'dateTime': startDate.toISOString(),
'timeZone': 'Australia/Melbourne'
},
'end': {
'dateTime': endDate.toISOString(),
'timeZone': 'Australia/Melbourne'
},
'recurrence': [
'RRULE:FREQ=DAILY;COUNT=2'
],
'reminders': {
'useDefault': false,
'overrides': [
{ 'method': 'email', 'minutes': 24 * 60 },
{ 'method': 'sms', 'minutes': 10 }
]
}
};
var request = gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': event
});
request.execute(function (event) {
appendPre('Added successfully!');
});
}
}