Use these instructions to set up API credentials for use with the syncing script.
The following instructions are based on the Create a project and enable the API and Create credentials articles.
To use the Google People API (formerly Contacts API), you need a Google Cloud Platform project. This project forms the basis for creating, enabling, and using all GCP services, including managing APIs, adding and removing collaborators, and managing permissions.
- Open the Google Cloud Console.
- Next to
Google Cloud Platform
, click the down arrow 🔽. A dialog listing current projects appears. - Click
New Project
. The New Project screen appears. - In the
Project Name
field, enter a descriptive name for your project. For example, enter "Google Monica Sync". - Click
Create
. The console navigates to the Dashboard page and your project is created within a few minutes.
- Next to "Google Cloud Platform," click the down arrow 🔽 and open your newly created project.
- In the top-left corner, click
Menu
>APIs & Services
. - Click
Enable APIs and Services
. TheWelcome to API Library
page appears. - In the search field, enter
People API
and press enter. - Click
Google People API
. The API page appears. - Click
Enable
. The "Overview" page appears.
Credentials are used to obtain an access token from a Google authorization server. This token is then used to call the Google People API. All Google Workspace APIs access data are owned by end-users.
The python script uses the OAuth protocol. When you start the script, it requests authorizations for read/write contacts
from a Google Account. Google then displays a consent screen to you including a summary of your created project and the requested scopes of access. You must configure this consent screen for the authentication to work.
To configure the OAuth consent screen:
- On the "Overview" page click
Credentials
. The credential page for your project appears. - Click
Configure Consent Screen
. The "OAuth consent screen" screen appears. - Select
External
as the user type for your app. - Click
Create
. A second "OAuth consent screen" screen appears. - Fill out the required form field (leave others blank):
- Enter "GMSync" in the
App name
field. - Enter your personal email address in theUser support email
field. - Enter your personal email address in theDeveloper contact information
field. - Click
Save and Continue
. The "Scopes" page appears. - Click
Add or Remove Scopes
. The "Update selected scopes" page appears. - Filter for "People API" and select the scope ".../auth/contacts".
- Click
Update
. A list of scopes for your app appears. Check if the scope ".../auth/contacts" is now listed in "Your sensitive scopes". - Click
Save and Continue
. The "Edit app registration" page appears. - At the "Test user" section click
Add Users
, enter the email of the Google Account whose contacts you want to sync, and clickAdd
.Hint: If you get a
403 forbidden
during consent later, you may have entered the wrong email here. - Click
Save and Continue
. The "OAuth consent screen" appears. - Click
Back to Dashboard
. - Back at the "OAuth consent screen" screen, click
PUBLISH APP
and thenCONFIRM
.This step is necessary because when in "Testing"-status, Google limits the token lifetime to seven days. You don't need to complete the app verification process.
- In the left-hand navigation, click
Credentials
. The "Credentials" page appears. - Click
Create Credentials
and selectOAuth client ID
. The "Create OAuth client ID" page appears. - Click the Application type drop-down list and select "Desktop application".
- In the name field, type a name for the credential. For example type "Python Syncing Script"
- Click
Create
. The "OAuth client created" screen appears. This screen shows the Client ID and Client Secret. - Click
DOWNLOAD JSON
. This copies a client secret JSON file to your desktop. Note the location of this file. - Rename the client secret JSON file to
credentials.json
.
- Install Python 3.9 or newer
- Copy
credentials.json
inside thedata
folder of the repository - In the main repository folder rename
.env.example
to.env
and fill in your desired settings (a Monica token can be retrieved in your account settings). - Do a
pip install -r requirements.txt
inside the main repository directory. - Open a command prompt inside the main repository directory and run
python GMSync.py -i
. - On the first run the script will print a Google consent URL in the console. Copy this URL and open it in a browser on the host machine.
- In your browser window, log in to your target Google account (the Google Account whose contacts you want to sync).
- At "Google hasn’t verified this app" click
Continue
. - At "GMSync wants access to your Google Account" click
Continue
. - An authorization code should have been transmitted via local server, follow the prompts in your terminal to complete the initial sync.
-
Install docker
-
In your chosen main folder, create two folders named
data
andlogs
. -
Copy
credentials.json
inside adata
folder of your main directory. -
Download the
.env.example
file, rename to.env
, put it in your main folder, and fill in your desired settings (a Monica token can be retrieved in your account settings).This project is using a non-root container, so
data
andlogs
must have read-write permissions for UID 5678 (container user). For example, you can usesudo chown -R 5678 data logs
orsudo chmod -R 777 data logs
inside your main directory to set the appropriate permissions. -
Open a command prompt inside the main directory run initial sync using the following command (on Windows replace
$(pwd)
with%cd%
)docker run -v "$(pwd)/data":/usr/app/data -v "$(pwd)/logs":/usr/app/logs -p 56411:56411 --env-file .env -it antonplagemann/google-monica-sync sh -c "python -u GMSync.py -i"
-
On the first run the script will print a Google consent URL in the console. Copy this URL and open it in a browser on the host machine.
-
In your browser window, log in to your target Google account (the Google Account whose contacts you want to sync).
-
At "Google hasn’t verified this app" click
Continue
. -
At "GMSync wants access to your Google Account" click
Continue
. -
An authorization code should have been transmitted via local server, follow the prompts in your terminal to complete the initial sync.