This quick-start app is built in Python and lets you get started with the Google+ Domains platform in a few minutes. The app demonstrates:
- Using domain-wide delegation of authority to get domain-wide access to user data.
- Making Google+ Domains API requests, including creating a new post for a designated user within the domain.
Requirements that are installed as part of this quick start:
Step 1: Enable domain-wide delegation of authority
Create the service account and its credentials
You must first create a service account. During this procedure the following credentials will be generated that your application will need the client ID, the private key, and the email address of the service account.
The following steps create a Google API Console project with credentials for a service account. The procedure generates credentials that your application will need: the client ID, the private key, and the email address of the service account.
- Go to the Google API Console .
- From the project drop-down, select a project , or create a new one.
Enable the Google+ Domains API service:
- In the list of Google APIs, search for the Google+ Domains API service.
- Select Google+ Domains API from the results list.
- Select Enable API.
In the sidebar under "APIs & Services", select Credentials, then select
the OAuth consent screen tab.
- Choose an Email Address, specify a Product Name, and select Save.
From the Credentials tab, select the New credentials drop-down list,
and choose Service account key.
- In the Service account drop-down, choose New service account.
- Enter a Name. The Service account ID is generated for you from the name you enter. You can accept this ID or override it. The Service account ID must be between 6 and 30 characters.
- Choose a Key type, then select the Create button.
- A "Service account created" dialog pops-up after successful creation/download. Select Close to return to the Credentials page.
- The Credentials page now displays a Service account keys section containing the service account ID, Creation date, and Service account name. To view the service account's Email address, select Manage service accounts to access the Permissions page. Note or copy these values to use in later steps to configure access to the API.
Delegate domain-wide authority to your service account
The service account must now be granted access to the user data for your Google Apps domain. The following tasks must be performed by an administrator of the Google Apps domain:
- Open your G Suite domain control panel, at https://www.google.com/a/cpanel/example.com.
- Click on the Security icon. This can sometimes be found in the More controls option.
- Go to Advanced settings > Authentication > Manage OAuth client access.
- In the Client Name field enter the service account's Client ID.
- In the One or More API Scopes field enter the scopes required for this sample.
- Click the Authorize button.
Step 2: Set up the Python quick-start app
Get the latest version of the quick-start. One way is to use git to clone the application repository.
git clone https://github.com/googleplus/gplus-domains-quickstart-python.git
Or, download the application as a zip file, and extract the library and sample code:
wget https://github.com/googleplus/gplus-domains-quickstart-python/archive/master.zip unzip gplus-domains-quickstart-python-master.zip
Change directory into the sample app:
Install the requirements of this quick start:
pip install -r requirements.txt
Copy the private key file you downloaded in Step 1 into the directory containing the
domain_delegation.pyfile. In this case, the directory is
domain_delegation.pyby making these changes:
SERVICE_ACCOUNT_EMAILto the value that you generated in Step 1.
SERVICE_ACCOUNT_PKCS12_FILE_PATHto the path to the private key file from the previous step. Include the filename.
USER_EMAILto the email address of the user you want to create a post on behalf of.
Step 3: Run the application
After you set up your Google API Console project and configure the sample app, the app is ready to run.
Run the Python quick-start app:
The application will request access to your domain's user data using domain-wide
delegation for the user account specified by
USER_EMAIL. The application then
uses the Python client library to create a new activity that
will appear on the user's profile, shared with the domain.
Now that you have learned to create a Google API Console project and run a sample app, you can learn more about the Google+ features you can add to your app: