1
votes

In our organisation, we use "Google Apps for Work" and I need periodically export all employees calendar data for automated statistics calculations of their time spend on meetings.

Could you hint me if it is possible? For now, the official solution I found require each user sign-in trough OAuth with granting permission to that my application to access their calendar, what is more, granted credentials will expire at some point.

However I need to achieve the same result but as "back-end service" with admin privileges without User sign in and app approval, is it possible? Or google calendar considered to be a private thing even for "Google Apps for Work" and each user need to grant permissions individually?

Thank you in advance! Regards

1

1 Answers

4
votes

However I need to achieve the same result but as "back-end service" with admin privileges without User sign in and app approval, is it possible?

What you're looking for are service accounts. With service accounts you are able to access data on behalf of users in a domain which is sometimes referred to as "delegating domain-wide authority". And fortunately enough, you can use this for Google Apps for Work.

If you have a Google Apps domain—if you use Google Apps for Work, for example—an administrator of the Google Apps domain can authorize an application to access user data on behalf of users in the Google Apps domain. For example, an application that uses the Google Calendar API to add events to the calendars of all users in a Google Apps domain would use a service account to access the Google Calendar API on behalf of users

Here's a snippet using Python when using a P12 file:

from oauth2client.service_account import ServiceAccountCredentials

client_email = '[email protected]'
scopes = ['https://www.googleapis.com/auth/sqlservice.admin']

credentials = ServiceAccountCredentials.from_p12_keyfile(
client_email, '/path/to/keyfile.p12', scopes=scopes)

Retrieving all calendar resources

To retrieve the first page of resource entries associated with a particular calendar, send an HTTP GET request ending with a forward slash to a resource feed URL. Include the Authorization header as described in Authenticating.

GET https://apps-apis.google.com/a/feeds/calendar/resource/2.0/{domain name}/

Optionally, you can send an HTTP GET request with an empty string in the start parameter to a resource feed URL.

GET https://apps-apis.google.com/a/feeds/calendar/resource/2.0/{domain name}/?start=""