Integrate Angular UI Calendar with Google Calendar
Posted By : Abhay Garg | 23-Dec-2014
Purpose -> You can Integrate Angular , in any Calendar (Create your own ) that you want , or even use Data of Google Calendar in your Project .
So for this purpose we use Oauth Access . If any problem then go to this link . I suppose that you have your Client ID . And enable Calendar API from google console
For this purpose you need this js https://apis.google.com/js/client.js
Java script code
angular.module('loginApp').controller('newCalendarCtrl', function ($scope, $log) {
var clientId = Your ID here as a String ;
var scopes = 'https://www.googleapis.com/auth/calendar';
function handleAuthResult(authResult) {
console.log(authResult);
var authorizeButton = document.getElementById('authorize-button');
if (authResult && !authResult.error) {
// authorizeButton.style.visibility = 'hidden';
makeApiCall();
} else {
authorizeButton.style.visibility = '';
authorizeButton.onclick = handleAuthClick;
}
}
$scope.handleAuthClick=function (event) {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
return false;
}
function makeApiCall() {
gapi.client.load('calendar', 'v3', function() {
var request = gapi.client.calendar.calendarList.list();
request.execute(function(resp){
$.each( resp.items, function( key, value ) {
console.log(resp.items[key].id);
});
});
var request1 = gapi.client.calendar.events.list({
'calendarId': 'primary',
'timeMin': '2015-12-23T04:26:52.000Z'//Suppose that you want get data after 23 Dec 2014
});
request1.execute(function(resp){
$.each( resp.items, function( key, value ) {
console.log(resp.items[key].id);// here you give all events from google calendar
});
});
});
}
});
HTML code
<div ng-controller="newCalendarCtrl">
<button ng-click="handleAuthClick()">Authorize</button>
<script src="https://apis.google.com/js/client.js"></script>
</div>
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Abhay Garg
Abhay is a Grails Developer expertise in OptaPlanner and Angular js framework.