Android上的G +登录会抛出INVALID_CLIENT_ID

时间:2014-02-01 20:17:10

标签: google-api google-plus google-play-services

我正在尝试在我们的应用中实现G +登录,但是,尽管我一再更新客户端ID,并重新创建一个新的,我仍然会收到错误消息

I/GLSUser﹕ GLS error: INVALID_CLIENT_ID myemail@domain.com oauth2:https://www.googleapis.com/auth/plus.login

不确定是什么问题。我可以看到帐户列表弹出窗口,其他一切似乎也可以正常工作。我也仔细检查了我的客户ID。

[编辑]

以下是我正在使用的代码

    private void getGoogleAccessToken() {
        Bundle appActivities = new Bundle();
        appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES, "AddActivity BuyActivity");
        String scopes = "oauth2:server:client_id:number-randomness.apps.googleusercontent.com" + ":api_scope:"+ Scopes.PLUS_LOGIN;
        mGoogleToken = null;

        try {
            mGoogleToken = GoogleAuthUtil.getToken(this, mPlusClient.getAccountName(), scopes, appActivities);
        } catch (IOException transientEx) {
            // network or server error, the call is expected to succeed if you try again later.
            // Don't attempt to call again immediately - the request is likely to
            // fail, you'll hit quotas or back-off.
            Crouton.makeText(this, R.string.google_bad_boy, Style.ALERT).show();
        } catch (UserRecoverableAuthException e) {
            // Recover
            Crouton.makeText(this, R.string.google_bad_boy, Style.ALERT).show();
        } catch (GoogleAuthException authEx) {
            // Failure. The call is not expected to ever succeed so it should not be
            // retried.
            Crouton.makeText(this, R.string.google_not_allow_login, Style.ALERT).show();
        } catch (Exception e) {
            Crouton.makeText(this, R.string.google_not_allow_login, Style.ALERT).show();
//          throw new RuntimeException(e);
        }
    }

[编辑2]

看起来我在这段代码中获得了一个不成功的Activity结果:

    mGoogleButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!mPlusClient.isConnected()) {
                    mConnectionProgressDialog.show();
                    if (mConnectionResult != null) {
                        try {
                            mConnectionResult.startResolutionForResult(SplashActivity.this, REQUEST_CODE_RESOLVE_ERR);
                        } catch (IntentSender.SendIntentException e) {
                            // Try connecting again.
                            mPlusClient.connect();
                        }
                    } else {
                        mPlusClient.connect();
                    }
                }
            }
        });

2 个答案:

答案 0 :(得分:17)

确保您已在Google Developer Console中的项目设置中更新了同意屏幕上的详细信息。您需要确认您的(开发人员)电子邮件地址,并为您的应用程序提供一个名称,该名称将在权限确认屏幕中显示给用户。

虽然Google+快速入门指南(https://developers.google.com/+/quickstart/android)没有明确说明这一点,但您需要这样做(非常简单),否则您的设备上会出现INVALID_CLIENT_ID错误。

答案 1 :(得分:0)

最常见的原因是API控制台中的软件包名称或SHA1密钥与应用程序中的密钥不匹配。确保您使用与从客户端ID解压缩SHA1相同的密钥库,并检查包名称或密钥中是否没有空格(包括在开头或结尾)。

编辑:根据代码,你的范围是错误的。您从一开始就错过了https://www.googleapis.com/auth。唯一的范围是"裸" Luke" profile"和"电子邮件"。同样,捆绑包中请求的应用程序活动类型是URL格式的,因此您需要确保使用https:// ...

使用卡片显示活动结果,请确保再次调用getToken。使用Google Auth Util的流程实际上与PlusClient流程分开。您可以将一个视为客户端,一个视为服务器。如果解决方案是从getToken异常开始的,则需要再次调用getToken。如果它是从解析PlusClient的ConnectionResult开始的,则需要再次使用PlusClient.connect。因此,您的onClick代码可能与您的getToken设置无关。一般来说,请确保协调两者所要求的范围和应用程序活动 - 这里分析了Android的客户端和服务器流程:http://www.riskcompletefailure.com/2013/10/google-android-client-server-sign-in.html