如何使用FullCalendar将事件添加到Google日历

我搜索过FullCalendar文档并搜索过,但我无法找到如何使用FullCalendar将事件添加到Google日历。 我曾尝试将js Google API用于Google日历,但我对js很新,我还没有解决。 所以我的问题是:我有一个网站,其中我使用FullCalendar来管理Google日历,但我无法向其添加事件。 是否有人可以帮助我,也许有一个完整的工作示例? 非常感谢您的precoius帮助!

我有同样的问题。 我阅读了很多文档,最后我得到了一个有效的代码。 我在这里与你分享:

这是如何从Fullcalendar(我非常喜欢)在Google Cal中实际添加事件的方法:

首先:从FullCalendar获取一个自定义表格

$('#calendar').fullCalendar({ set all options : options, selectable: true, selectHelper: true, // here is the part : select: function(start, end) { modalbox(start.format(),end.format()); }, editable: true }); 

所以,当我选择一个时间范围时,我会制作一个模态框(这样我就可以自己管理输入)。 我在这里使用start.format(),以便DateTime已经在GoogleFormat中。

第二:创建你的表格

1 /我创建表单

(在模态窗口中)。 它将包含Google日历的所有信息。

   

2 /我获取数据并将其推送到AJAX中的新页面

这样页面就不会重新加载……

  

最后,此处将此事件推入GOOGLE CAL

这个PHP代码将写在文件calendrier_add.php中:(当然,首先你必须在这里下载API: https : //github.com/google/google-api-php-client :BEWARE:autoload。 php在src / Google中,root中的那个是rooten ...)

  ************************************************/ $client_id = '12345467-123azer123aze123aze.apps.googleusercontent.com'; // YOUR Client ID $service_account_name = '12345467-123azer123aze123aze@developer.gserviceaccount.com'; // Email Address in the console account $key_file_location = 'fullcalendar/google-api-php-client-master/API_Project-35c93db58757.p12'; // key.p12 to create in the Google API console if (strpos($client_id, "googleusercontent") == false || !strlen($service_account_name) || !strlen($key_file_location)) { echo "no credentials were set."; exit; } /** We create service access ***/ $client = new Google_Client(); /************************************************ If we have an access token, we can carry on. (Otherwise, we'll get one with the help of an assertion credential.) Here we have to list the scopes manually. We also supply the service account ************************************************/ if (isset($_SESSION['service_token'])) { $client->setAccessToken($_SESSION['service_token']); } $key = file_get_contents($key_file_location); $cred = new Google_Auth_AssertionCredentials( $service_account_name, array('https://www.googleapis.com/auth/calendar'), // ou calendar_readonly $key ); $client->setAssertionCredentials($cred); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } $_SESSION['service_token'] = $client->getAccessToken(); /******************************************** END OF GOOGLE API CONNECTION ********************************************/ /*********** AT LAAAAST, WE PUSH THE EVENT IN GOOGLE CALENDAR ***************/ // Get the API client and construct the service object. $service = new Google_Service_Calendar($client); // We get the calendar $calendarId = 'Google_login@gmail.com'; // or whatever calendar you like where you have editable rights /************* INSERT ****************/ $event = new Google_Service_Calendar_Event(array( 'summary' => $titre_event, 'location' => $where_event, 'description' => $content_event, 'start' => array( 'dateTime' => $start, //'2015-06-08T15:00:00Z' 'timeZone' => 'Europe/Paris', ), 'end' => array( 'dateTime' => $end, 'timeZone' => 'Europe/Paris', ), /* in case you need that : 'attendees' => array( array('email' => 'lpage@example.com'), array('email' => 'sbrin@example.com'), ),*/ 'reminders' => array( 'useDefault' => FALSE, 'overrides' => array( array('method' => 'email', 'minutes' => 20) ), ), )); $event = $service->events->insert($calendarId, $event); printf('Event created: %s', $event->htmlLink); ?> 

我花了一些时间,但它对我来说很好。 在我的脚本中,我可以通过更改calendarID来编写多个日历。 它应该现在添加到Fullcalendar,但我没有GIT帐户,Node或NPM。

最后一件事

这可能很奇怪,但是我做这项工作的最佳方式也是将我的API控制台电子邮件帐户添加到日历的共享用户中!(在我获得10个声誉之前无法发布图像...)

我正在尝试使用“renderEvent”事件,新事件在日历中创建,但它没有修复(即下次刷新页面时事件不存在)。 这是我的代码:

           Calendario   

记录添加事件的方法很好,请阅读: http : //fullcalendar.io/docs/google_calendar/

我假设您因API更改而无法添加事件:

2014年11月17日,Google关闭了他们的Calendar API的V1和V2,而FullCalendar依赖它们。 请升级到最新版本的FullCalendar或至少用这个文件替换gcal.js(可以使用FullCalendar v2.0.0)。 此外,现在还需要您自己的Google Calendar API密钥。

你使用的是最新版本吗?