This quick-start app is built in Java 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.
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 Java 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-java.git
Or, download the application as a zip file, and extract the library and sample code:
wget https://github.com/googleplus/gplus-domains-quickstart-java/archive/master.zip unzip gplus-domains-quickstart-java-master.zip
Change into the sample app directory
Copy the private key file you downloaded in Step 1 to a location in or relative to your app's classpath.
src/com/google/plus/samples/quickstart/domains/DomainDelegation.javaby making these changes:
SERVICE_ACCOUNT_EMAILto the value that you generated in Step 1.
SERVICE_ACCOUNT_PKCS12_FILE_PATHto the path where you copied the private key file to, including its filename. Omit the path if the file is on the classpath; otherwise use the relative path.
USER_EMAILto the email address of the user you want to create a post on behalf of.
Step 3: Run the application
After you have set up your Google API Console project and configured the sample app, the app is ready to run.
Compile the Java quick-start app:
mkdir bin javac -sourcepath src -d bin -classpath "lib/*" src/com/google/plus/samples/quickstart/domains/DomainDelegation.java
Run the compiled quick-start app:
java -classpath "bin:lib/*" com.google.plus.samples.quickstart.domains.DomainDelegation
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 Java 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+ Domains API features you can add to your app: