- Go to: https://script.google.com
- Click "New > New script"
- Copy the code from Code.gs into the newly created script and save the script
Before using this script you will need to add the apps script oauth2 library to the project.
- Click on the menu item "Resources > Libraries..."
- In the "Find a Library" text box, enter the script ID 1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF and click the "Select" button.
- Choose a version in the dropdown box (usually best to pick the latest version).
- Click the "Save" button.
You also need a google cloud service account to do the API calls.
- Click on the menu item "Resources > Cloud Platform Project..."
- Click the project link to go to the associated Cloud Platform Project.
- Go to the Contacts API page to enable the API.
- When the api is enabled Create a Service account.
- Enter a name and click the "Create" button.
- You dont need to add Service account permissions so click "Continue".
- Click "+Create Key" and in the side window click "Create" and save the JSON file on your computer.
- Click "Done" to finish creating the service account.
- Click the email adres of the service account.
- Click the "Edit" button and "Show domain-wide delegation".
- Enable G Suite Domain-wide Delegation and click "Save".
- Go to the manage oauth clients page in the google admin panel.
- For the Client Name enter the "client_id" from the json file stored on your computer in step 3.
- For the API Scopes enter: https://www.googleapis.com/auth/contacts
- Click "Authorise"
- Go back to the apps script, and update PRIVATE_KEY and CLIENT_EMAIL with the values from the json file stored on your computer in step 3.
- Update the userList with email adresses in your domain
- Save and run the script to see if it works.
- Click on the menu item "Edit > Current project's triggers"
- Choose which functions to run: syncUsers
- Select type of time based trigger: Day timer
- Click "Save"