2016-07-15 75 views
1

我使用完整的日曆進行網絡應用程序項目,並將其與我的客戶端的Google日曆同步,但目前只有公共日曆。Fullcalendar + Private google calendar

有沒有辦法與私人日曆同步?

注意:我們使用0auth標識並與Google帳戶同步。

感謝

回答

1

我認爲它會使用正確的授權私人日曆工作。

Authorizing requests with OAuth 2.0

所有請求的谷歌日曆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

希望這有助於!

0

我已經嘗試在後端用PHP,使用谷歌PHP客戶端庫來獲取事件,然後把它放到fullcalendar。這樣,它的工作。