Android上的G +登录会抛出INVALID_CLIENT_ID [英] G+ signin on android throws INVALID_CLIENT_ID
问题描述
我尝试在我们的应用程序中实现G +登录,但是,尽管已经多次更新客户端ID,并重新创建了新的客户端,但我仍然收到一个错误消息:
I / GLSUser:GLS错误: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);
字符串范围=oauth2:server:client_id:number-randomness.apps.googleusercontent.com+:api_scope:+ Scopes.PLUS_LOGIN;
mGoogleToken = null;
尝试{
mGoogleToken = GoogleAuthUtil.getToken(this,mPlusClient.getAccountName(),scopes,appActivities);
} catch(IOException transientEx){
//网络或服务器错误,如果您稍后再尝试,预计调用会成功。
//不要立即尝试再次调用 - 请求很可能是
//失败,您将获得配额或退款。
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){
//失败。调用不会成功,因此它不应该
//重试。
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();
//抛出新的RuntimeException(e);
}
}
看起来我在这段代码中得到了一个不成功的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){
/ /再次尝试连接
mPlusClient.connect();
}
} else {
mPlusClient.connect();
}
}
}
});
确保您已更新您的同意信息在Google Developer控制台中显示您的项目设置。您需要确认您的(开发人员)电子邮件地址,并为您的应用程序提供一个名称,这些名称将在权限确认屏幕中显示给用户。
虽然Google+快速入门指南( https://developers.google .com / + / quickstart / android )并没有明确地说明这一点,你需要做到这一点(非常简单),否则你的设备上会收到INVALID_CLIENT_ID错误。
I am trying to implement G+ sign in, in our app, however, despite having repeatedly updating the client id, and recreating a new one as well, I keep on getting an error saying
I/GLSUser﹕ GLS error: INVALID_CLIENT_ID myemail@domain.com oauth2:https://www.googleapis.com/auth/plus.login
Not sure what's wrong. I can see the account list popup, and everything else seems to work as well. I have double checked my client id as well.
[EDIT]
Here is the code I am using
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);
}
}
[EDIT 2]
Seemingly I an getting a not successful result for Activity in this code:
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();
}
}
}
});
Make sure you've updated your details on the Consent Screen in your project settings in the Google Developer console. You need to confirm your (developer) email address, and provide a name for your app which will be displayed to the user in the permissions confirmation screen.
While the Google+ QuickStart guide (https://developers.google.com/+/quickstart/android) doesn't talk about this explicitly, you need to do this (very simple), else you'll get an INVALID_CLIENT_ID error on your device.
这篇关于Android上的G +登录会抛出INVALID_CLIENT_ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!