In this article, we will look into the setup details for integrating integrating Google+ into your Android app.
Before you can start integrating Google+ features in your own app, you must create a Google Developers Console project and initialize the GoogleApiClient within your app.
Our initial setup consists of:
- You must create a Google Developers Console project
- Enable the Google+ API
- Create an OAuth 2.0 Client ID
Create Google Developers Console Project
Go to the Google Developers Console. If the project is already created select it, else click on ‘Create Project’. Enter the project name and click on ‘Create’ button to create the project.
You can see the newly created project in the left side list.
Enable Google APIs
In the left sidebar, select APIs & auth. Click on APIs. Click on ‘Enable APIs’.
In the ‘Social APIs’ section, click on ‘Google + API’.
Click on ‘Enable API’.
After enabling, the button changes to ‘Disable API’.
OAuth 2.0 client ID – Request User Consent
Each request to an API that is represented in the Google Developers Console must include a unique identifier. Unique identifiers enable the Developers Console to couple requests to specific projects. Once can generate a unique identifier either through OAuth 2.0 access token or API Key.
You must use either an OAuth 2.0 access token or an API key for all requests to Google APIs represented in the Google Developers Console. We will see both the methods here.
First we will see API Key.
Click on ‘Add Credentials’
Configure Consent Screen.
In the OAuth Consent Screen, enter an Email Address and specify a Product Name. Click on save.
OAuth 2.0 Protocol – Create Client ID
If your application uses OAuth 2.0 protocol to call Google APIs, then you need to use OAuth 2.0 client ID to generate an access token. The token contains a unique identifier.
Select the application type as ‘Android’. Enter SHA and then click on ‘Create’ to create the client ID. We will see in the next section, how to generate SHA.
Generate SHA
Enter below command to generate SHA. The command uses the Keytool utility to get the SHA-1 fingerprint of the certificate. You need to specify path to debug.keystore
, the password is android
.
C:\Program Files\Java\jdk1.8.0_25\bin>keytool -exportcert -alias androiddebugkey -keystore C:\Users\{YourUserName}\.android/debug.keystore -list -v
API Key
Not all Google API calls require authorization. If an API call doesn’t require authorization, so it doesn’t need an access to user data then we don’t need OAuth 2.0 access token in which case you only need an API Key.
An API key is a unique identifier that you generate using the Developers Console. API keys do not grant access to any account information, and are not used for authorization so using an API key does not require user action or consent. However, if your application already uses an OAuth 2.0 access token, then there is no need to generate an API key as well and simply use OAuth 2.0 access token.
In this section we see how to generate an API Key for Android. Go to APIs & Auth->Credentials. Click on API key.
Next, click on Android Key.
Enter package name and SHA, and then click on ‘Create’.
An API Key is generated for you.
If you want to see your generated keys (API Key or Client ID), go to APIs & Auth->Credentials. You will see both the generated keys listed there.