在MVC中的Google日历中添加日期 [英] Add date in Google calender in MVC
本文介绍了在MVC中的Google日历中添加日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨专家,
我想在我的mvc应用程序中为google联系人添加谷歌日历
我需要的是我有一个日期文本框和一个按钮,用于将此日期添加到谷歌日历。我不知道我是如何实现这一点的。如果任何人有相同的代码发送给我。
谢谢
< b>我尝试了什么:
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"];
/**
* Check if current user has authorized this application.
*/
function checkAuth() {
alert('aa');
gapi.auth.authorize(
{
'client_id': CLIENT_ID,
'scope': SCOPES,
'immediate': true
}, handleAuthResult);
}
$("#GotoAuthSubLink").click(function () {
handleAuthClickResult(event)
});
/**
* Handle response from authorization server.
*
* param {Object} authResult Authorization result.
*/
function handleAuthResult(authResult) {
alert('bb');
var authorizeDiv = document.getElementById('GotoAuthSubLink');
if (authResult.error) {
// Hide auth UI, then load client library.
// authorizeDiv.style.display = 'none';
} else {
// Show auth UI, allowing the user to initiate authorization by
// clicking authorize button.
authorizeDiv.style.display = 'inline';
}
}
function handleAuthClickResult(authResult) {
alert('yes');
var authorizeDiv = document.getElementById('GotoAuthSubLink');
if (authResult && !authResult.error) {
// Hide auth UI, then load client library.
//authorizeDiv.style.display = 'none';
loadCalendarApi();
} else {
// Show auth UI, allowing the user to initiate authorization by
// clicking authorize button.
authorizeDiv.style.display = 'inline';
appendPre('Please try later!');
}
}
/**
* Initiate auth flow in response to user clicking authorize button.
*
* param {Event} event Button click event.
*/
function handleAuthClick(event) {
gapi.auth.authorize(
{client_id: CLIENT_ID, scope: SCOPES, immediate: false},
handleAuthClickResult);
return false;
}
/**
* Load Google Calendar client library. List upcoming events
* once client library is loaded.
*/
function loadCalendarApi() {
gapi.client.load('calendar', 'v3', addEventToGoogleCalendar);
}
/**
* Handle response from authorization server.
*
* param {string} message Text to be placed in pre element.
*/
function appendPre(message) {
document.getElementById('calendarOutput').innerHTML = message;
alert(message);
}
function addEventToGoogleCalendar() {
// Refer to the JavaScript quickstart on how to setup the environment:
// https://developers.google.com/google-apps/calendar/quickstart/js
// Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any
// stored credentials.
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!');
});
}
}
推荐答案
( #GotoAuthSubLink)。click(function(){
handleAuthClickResult( event )
});
/ * *
*处理来自授权服务器的响应。
*
* param {Object} authResult授权结果。
* /
函数handleAuthResult(authResult){
alert(' BB 跨度>);
var authorizeDiv = document.getElementById(' GotoAuthSubLink'跨度>);
if (authResult.error){
// 隐藏身份验证UI,然后加载客户端库。
// authorizeDiv。 style.display ='none';
} else {
// 显示auth UI,允许用户通过
发起授权 // 点击授权按钮。
authorizeDiv.style.display = ' 直列'跨度>;
}
}
函数handleAuthClickResult(authResult){
alert(' 是跨度>);
var authorizeDiv = document.getElementById(' GotoAuthSubLink'跨度>);
if (authResult&&!authResult.error){
// 隐藏auth UI,然后加载客户端库。
// authorizeDiv.style.display ='none';
loadCalendarApi();
} 其他 {
// 显示身份验证用户界面,允许用户通过
// 启动授权点击授权按钮。
authorizeDiv.style.display = ' inline';
appendPre(' 请稍后再试!');
}
}
/ * *
*启动auth流以响应用户单击授权按钮。
*
* param {Event}事件按钮点击事件。
* /
函数handleAuthClick( event ){
gapi.auth.authorize(
{client_id:CLIENT_ID,范围:SCOPES,立即: false },
handleAuthClickResult);
return false ;
}
/ * *
*加载Google日历客户端库。列出即将发生的事件
*加载客户端库后。
* /
函数loadCalendarApi(){
gapi.client.load(' calendar',' v3',addEventToGoogleCalendar);
}
/ * *
*处理来自授权服务器的响应。
*
* param {string} message要放在pre元素中的文本。
* /
函数appendPre(message){
document.getElementById(' calendarOutput')。innerHTML = message;
alert(message);
}
function addEventToGoogleCalendar(){
// 请参阅有关如何设置环境的JavaScript快速入门:
// https: //developers.google.com/google-apps/calendar/quickstart/js
// 将范围更改为https://www.googleapis.com/auth/calendar并删除任何
// 存储的凭证。
var date =
("#GotoAuthSubLink").click(function () { handleAuthClickResult(event) }); /** * Handle response from authorization server. * * param {Object} authResult Authorization result. */ function handleAuthResult(authResult) { alert('bb'); var authorizeDiv = document.getElementById('GotoAuthSubLink'); if (authResult.error) { // Hide auth UI, then load client library. // authorizeDiv.style.display = 'none'; } else { // Show auth UI, allowing the user to initiate authorization by // clicking authorize button. authorizeDiv.style.display = 'inline'; } } function handleAuthClickResult(authResult) { alert('yes'); var authorizeDiv = document.getElementById('GotoAuthSubLink'); if (authResult && !authResult.error) { // Hide auth UI, then load client library. //authorizeDiv.style.display = 'none'; loadCalendarApi(); } else { // Show auth UI, allowing the user to initiate authorization by // clicking authorize button. authorizeDiv.style.display = 'inline'; appendPre('Please try later!'); } } /** * Initiate auth flow in response to user clicking authorize button. * * param {Event} event Button click event. */ function handleAuthClick(event) { gapi.auth.authorize( {client_id: CLIENT_ID, scope: SCOPES, immediate: false}, handleAuthClickResult); return false; } /** * Load Google Calendar client library. List upcoming events * once client library is loaded. */ function loadCalendarApi() { gapi.client.load('calendar', 'v3', addEventToGoogleCalendar); } /** * Handle response from authorization server. * * param {string} message Text to be placed in pre element. */ function appendPre(message) { document.getElementById('calendarOutput').innerHTML = message; alert(message); } function addEventToGoogleCalendar() { // Refer to the JavaScript quickstart on how to setup the environment: // https://developers.google.com/google-apps/calendar/quickstart/js // Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any // stored credentials. var date =
( #datepicker3)。val();
alert(date);
if (date.length < 6 ){
appendPre( 选择日期);
} else {
var parts = date.split( ' /');
var startDate = new 日期(部件[ 2 ],部件[ 1 ] - 1 ,部件[ 0 跨度>]);
var endDate = new 日期(startDate.getTime()+( 12 * 1000 * 60 * 60 跨度>));
var eventAddress =
("#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 =
("#lblUserDetails").val(); var eventName =
这篇关于在MVC中的Google日历中添加日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文