2016-07-15 3 views
1

Я использую полный календарь для проекта веб-приложения, и я синхронизирую его с календарем Google моего клиента, но на данный момент доступен только общедоступный календарь.Fullcalendar + Частный календарь Google

Есть ли способ синхронизации с частным календарем?

Примечание: Мы используем 0auth для идентификации и синхронизации с учетной записью Google.

Благодаря

ответ

1

Я думаю, что он будет работать с частным календарем с помощью правильного разрешения.

Authorizing requests with OAuth 2.0

Все запросы к API Google Calendar должны быть авторизованы пользователем, прошедшим аутентификацию.

Здесь приведен пример создания с помощью 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, используйте библиотеку клиентских программ Google для получения событий, а затем поместите их в fullcalendar. Таким образом, он работает.