首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >完整日历+私人谷歌日历

完整日历+私人谷歌日历
EN

Stack Overflow用户
提问于 2016-07-15 22:00:39
回答 2查看 1.4K关注 0票数 1

我正在使用完整的日历用于一个web应用程序项目,并将其与我的客户的google日历同步,但目前只有公共日历。

是否有任何方法与私人日历同步?

备注:我们使用0auth来识别和同步Google。

谢谢

EN

回答 2

Stack Overflow用户

发布于 2016-07-17 14:09:05

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

使用OAuth 2.0授权请求

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

下面是亚历山大创建的示例

代码语言:javascript
复制
<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>

执行Google应用程序域范围的授权委托

在企业应用程序中,您可能希望以编程方式访问用户数据,而不需要用户的任何手动授权。在Google领域,域管理员可以授予第三方应用程序域范围内对其用户数据的访问--这称为域范围的授权。要以这种方式委派权限,域管理员可以在OAuth 2.0中使用服务帐户。 有关更多详细信息,请参见服务器对服务器应用程序使用OAuth 2.0

希望这能有所帮助!

票数 2
EN

Stack Overflow用户

发布于 2017-11-14 13:07:50

我已经尝试过在后端使用php,使用google客户端库获取事件,然后将其放入完整日历中。这样就行了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38405570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档