I followed below steps as this link
My project level gradle file :
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
}
My app level gradle file :
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services-identity:8.3.0'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile 'com.google.android.gms:play-services-auth:8.3.0'
...
}
I created OAuth 2.0 client ID for my backend server and pass this Client ID to strings.xml file.
And finally I created GoogleSignInOptions and GoogleApiClient objects as below :
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken(getString(R.string.server_client_id))
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
But the problem is result.isSuccess() always returns false in handleSignInResult function. I'm thinking maybe I'm doing somethings wrongly in 1th or 2nd step. And my codes are almost similar to this SignInActivity.java. Any help would be appreciated.
As I have answered at the following question:
In order to request Id Token sucessfully, you should use a "Web application" type Client Id, instead of "Android" type Client Id.
You also find at Google's documentation, the following info (please note #3):
Create an OAuth 2.0 client ID for your backend server
If your app authenticates with a backend server or accesses Google APIs from your backend server, you must create an OAuth 2.0 client ID for your server. To create an OAuth 2.0 client ID:
- Open the Credentials page.
- Click Add credentials > OAuth 2.0 client ID.
- Select Web application.
- Click Create.
Pass this client ID to the requestIdToken or requestServerAuthCode method when you create the GoogleSignInOptions object.
Update Mar 26:
Android Developers Blog - Registering OAuth clients for Google Sign-In