We\'re under Android (Jellybean and higher), and we\'ve got an app which need to use OAuth2 with Google for authentication.
I simplified the login activity, but it\'
Don't have the reputation to comment on the accepted answer...
Registering my app in the google dev console wasn't working for me. It turned out that since I was using the debug gradle build, I had to append ".debug" to the package name in google dev console.
I found this out by debugging the Android AccountManager code. When I stepped into the code, I noticed the variable for my app's package name had ".debug" at the end of it. So instead of using the actual package name "com.package.name" in the google dev console, I changed it to "com.package.name.debug" which fixed the UNREGISTERED_ON_API_CONSOLE exception for me.
The reason for this is because my debug buildType in gradle had 'applicationIdSuffix ".debug"'.
Well, I finally figured it out. Not sure if I misread the documentation or if there are missing links, but anyway.
Fact is that when you sign a APK and then ask Google for a OAuth2 token, you have to register your signed app through the dev console. It's a security measure based on the app package name and the sha1 fingerprint.
To do that, you have to :
signingReport task under your root project and run it - the SHA1 fingerprint will show in the text output;And voila!
For information, the only official documentation I found explaining the why and how of the two final steps is here: https://developers.google.com/drive/android/auth
Thanks Xavier Portebois, your answer really helped. I had to do two more steps.
Thanks for the informative answer!
For anyone still struggling with this, here's what worked for me:
If you enroll your app into the Google Play App Signing program, then your KeyStore is not used de facto to sign the application once it reaches the play store - that's why the fingerprints don't match.
Google removes your certificate and creates a new signing certificate that is used to sign your APK.
In the Play Console go to Release Management -> App signing
If you opted in to Google Play App Signing, you'll see 2 certificates there along with all of their fingerprints. Use the App Signing Certificate fingerprint instead of the Upload Certificate which is your KeyStore.
For me, the solutions above don't work at all. I finally figure out the bug by myself. I have several folders in my work space and each of them has their own Manifest.xml file, which means their have different package names. In this case, when we register on Google API, we have to use the package name in file build.gradle, the property applicationId. Then here it is.
For me, the problem was Signing-certificate fingerprint (SHA-1) of the debug app and the release app does not match when I upgrade app and change package name. I've wasted days checking package name then figure out the problem is the package name.
To get correct SHA-1 key, follow this S.O post, then use this key to create a new OAuth client ID for your app.