Fullcalendar +私人谷歌日历

时间:2016-07-15 22:00:39

标签: fullcalendar google-calendar-api

我正在使用完整日历用于网络应用项目,并将其与我的客户端的谷歌日历同步,但目前仅公开日历。

有没有办法与私人日历同步?

注意: 我们使用0auth识别并与Google帐户同步。

由于

2 个答案:

答案 0 :(得分:1)

我认为使用正确的授权可以使用私人日历。

Authorizing requests with OAuth 2.0

  

对Google Calendar API的所有请求必须由经过身份验证的用户授权。

以下是Alexandre创建的示例:

<script type="text/javascript">

            var clientId = '<your-client-id>';
            var apiKey = '<your-api-key>';
            var scopes = 'https://www.googleapis.com/auth/calendar';

            function handleClientLoad() {
                gapi.client.setApiKey(apiKey);
                window.setTimeout(checkAuth,1);
            }

            function checkAuth() {
                gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
            }

            function handleAuthResult(authResult) {
                var authorizeButton = document.getElementById('authorize-button');

                if (authResult && !authResult.error) {
                    authorizeButton.style.visibility = 'hidden';          
                    makeApiCall();
                } else {
                    authorizeButton.style.visibility = '';
                    authorizeButton.onclick = handleAuthClick;
                    GeneratePublicCalendar();
                }
            }

            function handleAuthClick(event) {            
                gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
                return false;
            }


            // Load the API and make an API call.  Display the results on the screen.
            function makeApiCall() {

                // Step 4: Load the Google+ API
                gapi.client.load('calendar', 'v3').then(function() {
                  // Step 5: Assemble the API request
                      var request = gapi.client.calendar.events.list({
                            'calendarId': '<your-calendar-id(The @gmail.com>'
                        });

                        // Step 6: Execute the API request
                        request.then(function(resp) {

                            var eventsList = [];
                            var successArgs;
                            var successRes;

                            if (resp.result.error) {
                                reportError('Google Calendar API: ' + data.error.message, data.error.errors);
                            }
                            else if (resp.result.items) {
                                $.each(resp.result.items, function(i, entry) {
                                    var url = entry.htmlLink;

                                    // make the URLs for each event show times in the correct timezone
                                    //if (timezoneArg) {
                                    //    url = injectQsComponent(url, 'ctz=' + timezoneArg);
                                    //}

                                    eventsList.push({
                                        id: entry.id,
                                        title: entry.summary,
                                        start: entry.start.dateTime || entry.start.date, // try timed. will fall back to all-day
                                        end: entry.end.dateTime || entry.end.date, // same
                                        url: url,
                                        location: entry.location,
                                        description: entry.description
                                    });
                                });

                                // call the success handler(s) and allow it to return a new events array
                                successArgs = [ eventsList ].concat(Array.prototype.slice.call(arguments, 1)); // forward other jq args
                                successRes = $.fullCalendar.applyAll(true, this, successArgs);
                                if ($.isArray(successRes)) {
                                    return successRes;
                                }
                            }

                            if(eventsList.length > 0)
                            {
                              // Here create your calendar but the events options is :
                              //fullcalendar.events: eventsList (Still looking for a methode that remove current event and fill with those news event without recreating the calendar.

                            }
                          return eventsList;

                      }, function(reason) {
                        console.log('Error: ' + reason.result.error.message);
                      });
                });
            }

function GeneratePublicCalendar(){  
  // You need a normal fullcalendar with googleApi when user isn't logged

    $('#calendar').fullCalendar({
                    googleCalendarApiKey: '<your-key>',      
      ...
    });  
}
</script>
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>

Perform Google Apps Domain-Wide Delegation of Authority

  

在企业应用程序中,您可能希望以编程方式访问用户数据,而无需他们进行任何手动授权。在Google Apps域中,域管理员可以向第三方应用程序授予对其用户数据的域范围内访问权限 - 这称为域范围的授权。要以这种方式委派权限,域管理员可以将服务帐户与OAuth 2.0一起使用。

     

有关其他详细信息,请参阅Using OAuth 2.0 for Server to Server Applications

希望这有帮助!

答案 1 :(得分:0)

我已经尝试在后端使用php,使用google php客户端库获取事件,然后将其放入fullcalendar。这样就可以了。