I am just trying to authenticate for Android Drive API.
I Generated Signed APK from Android Studio. The account get authenticated and Google Drive API Authentication works perfectly with this generated APK.
Now when I Upload this same APK to Internal Test in Play Console. Then the authentication fails.
__ Now Here is how I Done all this__
1) Added following in the Android Manifest
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
2) Implemented the Authentication like this
public abstract class AuthActivityStackOverflow extends BaseActivity {
protected static final int GOOGLE_SIGN_IN_REQUEST_CODE = 1;
public void signIn() {
startActivityForResult( getGoogleSignInClient().getSignInIntent(), GOOGLE_SIGN_IN_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GOOGLE_SIGN_IN_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
onSignInSuccess(GoogleSignIn.getLastSignedInAccount(this), requestCode);
showMessage("Account Linked Successfully");
} else { onSignInFailed(); }
}
}
protected GoogleSignInClient getGoogleSignInClient(){
GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(Drive.SCOPE_APPFOLDER)
.requestEmail()
.build();
return GoogleSignIn.getClient(this, signInOptions);
}
}
3) I generated the debug key SHA1 and registered the credentials with API Console and then tested the app. Its working here. (onActivityResult returns RESULT_OK)
4) Now I generated the production key SHA1 and registered the credentials with API Console and Generated the final signed APK from Android Studio and tested on my physical device. Its still working. (onActivityResult returns RESULT_OK)
5) Now I published this final production APK to internal test in Play Console.
6) NOW when i download this app and run this authentication. It FAILS, now its not working. (onActivityResult returns "0")
Is there anything that I am missing on.
All the steps that I carried out as stated in my question are correct. I just missed on one thing and that is I am using "App Signing by Google Play".
When using "App Signing by Google Play" we need to create credential - OAuth client ID by using SHA-1 of the App signing certificate inside credentials in API Console.
Now where to get this SHA-1 of the - App signing certificate?
That's it. Now when you run the application an make the API call it will work.