This quick-start sample app is built in Go 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.
Step 1: Enable the Google+ API
- Go to the Google Developers Console .
or create a new one by clicking Create Project:
Note: Use a single project to hold all platform instances of your app (Android, iOS, web, etc.), each with a different Client ID.
- In the Project name field, type in a name for your project.
- In the Project ID field, optionally type in a project ID for your project or use the one that the console has created for you. This ID must be unique world-wide.
- Click the Create button and wait for the project to be created.
- Click on the new project name in the list to start editing the project.
- In the left sidebar, select the APIs item below "APIs & auth". A list of Google web services appears.
- Find the Google+ API service and set its status to ON—notice that this action moves the service to the top of the list. You can turn off the Google Cloud services.
In the sidebar under "APIs & auth", select Consent screen.
- Choose an Email Address and specify a Product Name.
- In the sidebar under "APIs & auth", select Credentials.
Click Create a new Client ID — a
dialog box appears.
Register the origins from which your app is allowed to access the Google APIs, as follows. An origin is a unique combination of protocol, hostname, and port.
- In the Application type section of the dialog, select Web application.
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.
- Click the Create Client ID button.
- In the resulting Client ID for web application section, copy the Client ID and Client secret that your app will need to use to access the APIs.
Step 2: Set up the Go 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-quickstart-go.git
Or, download the application as a zip file, and extract the quick-start code:
wget https://github.com/googleplus/gplus-quickstart-go/archive/master.zip -o gplus-quickstart-go.zip unzip gplus-quickstart-go.zip
Change directory into the quick-start app:
YOUR_CLIENT_SECRETwith the values that you generated in Step 1.
Step 3: Install the necessary libraries for Go
Download and install the Google+ API library for Go:
go get github.com/google/google-api-go-client/plus/v1
Download and install the OAuth 2.0 library:
go get golang.org/x/oauth2 go get golang.org/x/oauth2/google
Download and install the Gorilla web toolkit to manage sessions:
go get github.com/gorilla/sessions
Step 4: Run the quick-start app
Now that you have set up your Google Developers Console project and configured the quick-start app, the app is ready to run.
Because you registered
http://localhost:4567 as a Web origin in the
Google Developers Console, you will run the sample from that
Run the Go quick-start app:
go run main.go
Browse to your quick-start app, which by default is at http://localhost:4567.
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.