【问题标题】:GoogleAuthUtil.getToken gives com.google.android.gms.auth.GoogleAuthException: UnknownGoogleAuthUtil.getToken 给出 com.google.android.gms.auth.GoogleAuthException: Unknown
【发布时间】:2014-01-31 23:26:41
【问题描述】:

我的目标是在不进行任何服务器端工作的情况下获取用户的基本个人资料信息(名字、姓氏等)。而且我不想在用户界面上使用 Google+ 登录按钮。

我可以毫无问题地收到用户的电子邮件。所以下一步是获取访问令牌来获取配置文件,这是我的代码

    String token = null;
    try {
        token = GoogleAuthUtil.getToken(getApplicationContext(), email, SCOPE);
    } catch (final UserRecoverableAuthException e) {
        startActivityForResult(e.getIntent(), REQUEST_CODE_AUTH_GOOGLE_ACCOUNT);
    } catch (IOException e) {
        Log.e(TAG, e.toString());
    } catch (GoogleAuthException e) {
        Log.e(TAG, e.toString());
    }

我已经定义了范围

private static final String SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile";

当我运行我的应用程序时,出现“com.google.android.gms.auth.GoogleAuthException: Unknown”异常。我也尝试过其他范围,例如 Scope.PLUS_LOGIN、Scope.PLUG_PROFILE。但他们都给了我同样的例外。

顺便说一句,在 Google API 控制台中,我已经设置了一个客户端 ID。

我已经坚持了 2 天。任何帮助将非常感激。

【问题讨论】:

    标签: android google-authentication


    【解决方案1】:

    我认为你做错了。我就是这样做的:

    scopes.add(AnalyticsScopes.ANALYTICS_READONLY);
    
                    credential = GoogleAccountCredential.usingOAuth2(this, scopes);
                    if (TextUtils.isEmpty(appPreferences.getUserName()))
                    {
                            try
                            {
    
                                    startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
                            }
                            catch (ActivityNotFoundException e)
                            {
    
                                    Toast.makeText(this, getString(R.string.gps_missing), Toast.LENGTH_LONG).show();
    
                                    return;
                            }
    
                    }
    

    在此处查看我的源文件: https://github.com/madhur/GAnalytics/blob/develop/src/in/co/madhur/ganalyticsdashclock/MainActivity.java

    【讨论】:

    猜你喜欢
    • 2015-03-17
    • 2015-01-12
    • 2014-09-27
    • 2017-06-10
    • 2015-03-28
    • 1970-01-01
    • 2018-09-06
    • 2017-05-07
    • 1970-01-01
    相关资源
    最近更新 更多