Google Setup Service Account

1116 Views

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.

Step 1
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.

Step 2
Click the Credentials link pictured below then click the Create Credentials button. Select Service Account Key.

Google service account pic 1

On the next screen pictured below select the first option and check JSON and click Create.

Screen Shot 2016-07-31 at 2.57.05 PM

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.

Step 3
Click the Credentials side menu, this will list your new credential. Next to your newly created credential copy the Client ID

Step 4
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.

Please Post Your Comments & Reviews

Welcome to Western Studios

We provide professional website and mobile softwares including Joomla, Wordpress and more.