While developing a PHP Google Calendar and Drive integration I was tasked with using a Service Account. Finding documents on how to integrate became a hassle without clear details on how to accomplish what I needed.
In this tutorial I will show you how to setup a Google API Service Account and use with your PHP integration. This also applies for other languages.
Before we begin you must have a Google Apps Work account and logged in here https://apps.google.com
It is important for the next steps that you login using the main account and not a sub user.
Log into the Google Console and setup your new app, select the apps you will use. In my example I am using Calendar and Drive so set those to active.
Click the Credentials link pictured below then click the Create Credentials button. Select Service Account Key.
On the next screen pictured below select the first option and check JSON and click Create.
You will be prompted to save a JSON file, rename it to service-account.json and save to your desktop, you will need this later in the tutorial.
Click the Credentials side menu, this will list your new credential. Next to your newly created credential copy the Client ID
Log back into your Google Apps for Work account and go to the admin console https://admin.google.com
Click the Security icon. Next click Show more then click Advanced Settings.
Click Manage API client access. The next page allows you to add different scopes to your client id and give domain wide authentication.
Enter the Client ID you copied earlier from the Google Console and paste into the Client Name field.
In the One or More API Scopes enter your scopes separated by a comma. In my case it would be https://www.googleapis.com/auth/calendar,
https://www.googleapis.com/auth/drive for read/write access to Google Calendar and Google Drive.
Your API now has full access to Google Calendar and Google Drive.
Part 2 of the tutorial will show you how to integrate with your PHP application.
We do custom Google Apps integration with our fee $35/hr. Contact us for service.