Google+ Platform

Quick start for JavaScript

This quick-start app is built in JavaScript and lets you get started with the Google+ platform in a few minutes. The app demonstrates:

  • Using the Google+ Sign-In button to get an OAuth 2.0 refresh token.
  • Exchanging the refresh token for an access token.
  • Making Google+ API requests with the access token, including getting a list of people that the user has circled.
  • Disconnecting the app from the user's Google account and revoking tokens.

System requirements

Step 1: Enable the Google+ API

Create a Google APIs Console project, OAuth 2.0 client ID, and register your JavaScript origins:

  1. Go to the Google Developers Console.
  2. Select a project, or create a new one.
  3. In the sidebar on the left, select APIs & auth. APIs is automatically selected.
  4. In the displayed list of APIs, make sure the Google+ API status is set to ON.
  5. In the sidebar on the left, select Credentials.
  6. In the OAuth section of the page, select Create New Client ID.

    In the resulting Create Client ID dialog box, register the origins where your app is allowed to access the Google APIs. The origin is the unique combination of protocol, hostname, and port.

    1. In the Application type section of the dialog, select Web application.
    2. In the Authorized JavaScript origins field, enter the origin for your app. You can enter multiple origins to allow for your app to run on different protocols, domains, or subdomains. Wildcards are not allowed. In the example below, the second URL could be a production URL.
      http://localhost:4567
      http://myproductionurl.example.com
    3. Select Create Client ID.
    4. In the resulting Client ID for web application panel, note or copy the Client ID and Client secret that your app will need to use to access the APIs.

Step 2: Set up the JavaScript 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-quickstart-javascript.git
    

Or, download the application as a zip file, and extract the library and sample code:

    wget https://github.com/googleplus/gplus-quickstart-javascript/archive/master.zip
    unzip gplus-quickstart-javascript-master.zip
  1. Change directory into the sample app

    cd gplus-quickstart-javascript
    
  2. Edit index.html, and replace YOUR_CLIENT_ID with the value that you generated in Step 1.

Step 3: Run the application

After you have set up your Google API project and configured the sample app, the app is ready to run.

Because you registered http://localhost:4567 as an Authorized JavaScript origin in the Google APIs Console, you will run the sample from that location.

  1. Now you need to start a server. For example:

    python -m SimpleHTTPServer 4567
    
  2. Browse to your quick-start app, which by default is at http://localhost:4567.

After you sign in, the application uses the JavaScript client library to retrieve your profile, as well as the people visible to the app.

Clicking Disconnect from Google+ results in the server making a call to Google to revoke the refresh token. The server then removes any data that it acquired from Google about the user to disconnect the app and follow the developer policies.

Next steps

Now that you have learned to create an APIs console project and run a sample app, you can learn more about the Google+ features you can add to your app:

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.