com.google.android.gms.auth.GoogleAuthException:getToken(未知来源)异常

时间:2014-01-21 14:44:45

标签: android google-app-engine google-authentication

在我的Android应用程序中,我正试图在我的谷歌应用引擎后端服务器上验证谷歌令牌。但我总是得到这个例外:

com.google.android.gms.auth.GoogleAuthException: getToken(Unknown Source) exception

我的代码:

    private Account mAccount = AccountManager.get(this).getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE)[0];
    private static final String SCOPE = "audience:server:client_id:" +Constants.WED_CLIENT_ID;
    String token = GoogleAuthUtil.getToken(LoginActivity.this, mAccount.name, SCOPE);

我已经尝试过Stackoverflow中提出的每个解决方案。

3 个答案:

答案 0 :(得分:16)

几个小时后,我发现在您的范围字符串("audience:server:client_id:...")中,您必须使用Web应用程序的客户端ID,而不是Android应用程序。

Android应用的客户端ID未使用。只有在这里才能将Android应用程序的软件包名称与您的网络应用程序相关联。

答案 1 :(得分:15)

经过2天的研究,我发现当时您在Google云端控制台中注册Android应用程序 - >你的项目 - > API和身份验证,它会询问您指纹以生成ClientID,并且我的指纹错误(我在此cmd ~$之前意外添加了keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1)并且由于这个原因,它给了我错误的指纹和是根本原因:

com.google.android.gms.auth.GoogleAuthException: getToken(Unknown Source) exception.

答案 2 :(得分:2)

After reading couple of posts on the internet I generated SHA1 fingerprint value of my keystore as

keytool -exportcert -alias android_keystore -keystore android_keystore -list -v | openssl sha1

due to which I was getting that error. If you see the credentials screen in you google developer console it says you need to use

keytool -exportcert -alias android_keystore -keystore android_keystore -list -v

i.e Don't pipe the output to openssl sha1. Not sure what the difference is but both commands give different values.

You will get multiple fingerprints like MD5, SHA1, SHA256 etc. Use SHA1 value.

相关问题