Legacy Google+ APIs have been shut down as of March 7, 2019. Changes to the shutdown plan have been made recently which may mitigate its effect on some developers. Learn more.

Google+ integrations for web and mobile apps have also stopped functioning as of March 7, 2019. Learn more.

Quick start for Java

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.

System requirements

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.

  1. Go to the Google API Console .
  2. From the project drop-down, select a project , or create a new one.
  3. Enable the Google+ Domains API service:
    1. In the list of Google APIs, search for the Google+ Domains API service.
    2. Select Google+ Domains API from the results list.
    3. Select Enable API.
    When the process completes, Google+ Domains API appears in the list of enabled APIs. To access, select APIs & Services on the left sidebar menu, then select the Enabled APIs tab.
  4. In the sidebar under "APIs & Services", select Credentials, then select the OAuth consent screen tab.
    1. Choose an Email Address, specify a Product Name, and select Save.
  5. From the Credentials tab, select the New credentials drop-down list, and choose Service account key.
    1. In the Service account drop-down, choose New service account.
    2. 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.
    3. Choose a Key type, then select the Create button.
    Once generated, the public/private key pair file downloads to your machine. The file serves as the only copy of this key; you are responsible for storing it securely.
  6. A "Service account created" dialog pops-up after successful creation/download. Select Close to return to the Credentials page.
  7. 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:

  1. Open your G Suite domain control panel, at https://www.google.com/a/cpanel/example.com.
  2. Click on the Security icon. This can sometimes be found in the More controls option.
  3. Go to Advanced settings > Authentication > Manage OAuth client access.
  4. In the Client Name field enter the service account's Client ID.
  5. In the One or More API Scopes field enter the scopes required for this sample.
  6.   https://www.googleapis.com/auth/plus.me, https://www.googleapis.com/auth/plus.stream.write
  7. Click the Authorize button.

Step 2: Set up the Java quick-start app

  1. 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
  2. Change into the sample app directory

    cd gplus-domains-quickstart-java
  3. Copy the private key file you downloaded in Step 1 to a location in or relative to your app's classpath.

  4. Edit src/com/google/plus/samples/quickstart/domains/DomainDelegation.java by making these changes:

    • Set SERVICE_ACCOUNT_EMAIL to the value that you generated in Step 1.
    • Set SERVICE_ACCOUNT_PKCS12_FILE_PATH to 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.
    • Set USER_EMAIL to 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.

  1. Compile the Java quick-start app:

    mkdir bin
    javac -sourcepath src -d bin -classpath "lib/*" src/com/google/plus/samples/quickstart/domains/DomainDelegation.java
  2. 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.

Next steps

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:

Send feedback about...

Google+ Domains API
Google+ Domains API