Android Google Plus登录问题。handleSignInResult返回False
我在集成Google+Signin功能时遇到了一些问题。到目前为止,我已经集成了所有必要的G+登录API模块和代码,这些模块和代码运行良好,在使用debug.keystore的keytool生成SHA1后,生成了google-services.json并将其放置在/app中,并将SHA1粘贴到google cloud developer控制台上,但现在,我只面临一个问题,因为很多天/周以来,即当我尝试进行设备调试时,每当我单击“G+登录”时,我在LogCat中会出现以下错误: E/GMPM:getGoogleAppId失败,状态为10 E/GMPM:无法上载。应用程序测量已禁用 D/显著性:无手柄点火结果:错误 此handleSignInResult始终返回False,无法登录以进一步获取数据。如果你们中有人曾经遇到过这样的情况,请在这里帮助我。这个小小的障碍真让人恼火Android Google Plus登录问题。handleSignInResult返回False,android,google-api,google-plus,google-signin,Android,Google Api,Google Plus,Google Signin,我在集成Google+Signin功能时遇到了一些问题。到目前为止,我已经集成了所有必要的G+登录API模块和代码,这些模块和代码运行良好,在使用debug.keystore的keytool生成SHA1后,生成了google-services.json并将其放置在/app中,并将SHA1粘贴到google cloud developer控制台上,但现在,我只面临一个问题,因为很多天/周以来,即当我尝试进行设备调试时,每当我单击“G+登录”时,我在LogCat中会出现以下错误: E/GMPM:ge
谢谢大家。您是在API中使用Plus.API还是Auth.GOOGLE\u SIGN\u?后者是最新改进的。在这里查看:
如果您在API中使用Auth.GOOGLE\u SIGN\u: 在onActivityResult中,使用类似于下面的代码,您可以获得一个状态代码,该代码由GoogleSignInstateCodes定义: 最常见的问题是缺少正确的OAuth2客户端注册。(不幸的是,目前状态代码是内部错误8,这没有帮助。)例如,看看这个线程:
正如Sudhanshu Gaur在中指出的那样,首先尝试使用与以前相同的密钥生成一个签名的apk。然后将其安装到您的设备上,并查看其是否正常工作。原因是当您单击“运行”时,Android Studio没有签署您的apk。
我遇到了完全相同的问题,此修复对我来说效果很好。请确保您已在
google services.json
文件创建中应用了SHA-1
调试密钥。您需要在应用程序上提供签名证书的SHA-1哈希值
例如:
注册SHA-1:
CF:4A:A1:0A:BC:84:F2:31:28:C3:BA:A7:A3:A2:36:10:5F:1D:3E:CB
并下载您创建的配置文件。。并替换为
*yourproject/app/google-service.json
//获取google-service.json文件教程
//如何获得SHA-1
如果您在firebase中添加所有SHA-1指纹,仍然会出现错误。然后(我遇到了此问题。完成此步骤后,问题得到解决。)尝试以下步骤: 1.转到第页 2.单击左侧选项卡中的凭据 3.已经存在两个默认的Android和Web OAuth客户端Id。您必须创建一个Android客户端和一个Web2.0客户端 4.转到Firebase。在项目设置中,下载google-services.json并粘贴到应用程序文件夹中
(一切正常,但您仍然无法登录google意味着可能存在OAuth问题。因此,请确保创建Android和Web客户端ID。最后,在凭证页面中,您有两个Android客户端和两个Web客户端ID。)请检查您添加的SHA-1密钥是否调试或释放,基于您的密钥,它的工作相对而言是基于它的。 我有同样的问题拿铁,我知道我已经使用了版本SHA-1,我在调试测试,然后它会得到错误的结果。
谢谢首先生成调试密钥:
keytool -exportcert -list -v \
-alias androiddebugkey -keystore ~/.android/debug.keystore
然后将SHA1粘贴到指纹部分的Firebase或Google项目设置中。package com.Google.samples.quickstart.sign;
package com.google.samples.quickstart.signin;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
/**
* Activity to demonstrate basic retrieval of the Google user's ID, email address, and basic
* profile.
*/
public class SignInActivity extends AppCompatActivity implements
View.OnClickListener {
private static final String TAG = "SignInActivity";
private static final int RC_SIGN_IN = 9001;
private GoogleSignInClient mGoogleSignInClient;
private TextView mStatusTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_DEMO);
// Views
mStatusTextView = findViewById(R.id.status);
// Button listeners
findViewById(R.id.sign_in_button).setOnClickListener(this);
findViewById(R.id.sign_out_button).setOnClickListener(this);
findViewById(R.id.disconnect_button).setOnClickListener(this);
// [START configure_signin]
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
// [END configure_signin]
// [START build_client]
// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
// [END build_client]
// [START customize_button]
// Set the dimensions of the sign-in button.
SignInButton signInButton = findViewById(R.id.sign_in_button);
signInButton.setSize(SignInButton.SIZE_STANDARD);
signInButton.setColorScheme(SignInButton.COLOR_LIGHT);
// [END customize_button]
}
@Override
public void onStart() {
super.onStart();
// [START on_start_sign_in]
// Check for existing Google Sign In account, if the user is already signed in
// the GoogleSignInAccount will be non-null.
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
updateUI(account);
// [END on_start_sign_in]
}
// [START onActivityResult]
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
// [END onActivityResult]
// [START handleSignInResult]
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
// Signed in successfully, show authenticated UI.
updateUI(account);
} catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
updateUI(null);
}
}
// [END handleSignInResult]
// [START signIn]
private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
/* Intent sign = mGoogleSignInClient.getSignInIntent ();
startActivityForResult ( sign, RC_SIGN_IN );*/
}
// [END signIn]
// [START signOut]
private void signOut() {
mGoogleSignInClient.signOut()
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
// [START_EXCLUDE]
updateUI(null);
// [END_EXCLUDE]
}
});
}
// [END signOut]
// [START revokeAccess]
private void revokeAccess() {
mGoogleSignInClient.revokeAccess()
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
// [START_EXCLUDE]
updateUI(null);
// [END_EXCLUDE]
}
});
}
// [END revokeAccess]
private void updateUI(@Nullable GoogleSignInAccount account) {
if (account != null) {
mStatusTextView.setText(getString(R.string.signed_in_fmt, account.getDisplayName()));
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE);
} else {
mStatusTextView.setText(R.string.signed_out);
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE);
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
signIn();
break;
case R.id.sign_out_button:
signOut();
break;
case R.id.disconnect_button:
revokeAccess();
break;
}
}
}
导入android.content.Intent;
导入android.os.Bundle;
导入android.support.annotation.NonNull;
导入android.support.annotation.Nullable;
导入android.support.v7.app.AppActivity;
导入android.util.Log;
导入android.view.view;
导入android.widget.TextView;
导入com.google.android.gms.auth.api.signin.GoogleSignIn;
导入com.google.android.gms.auth.api.signin.GoogleSignInAccount;
导入com.google.android.gms.auth.api.signin.GoogleSignInClient;
导入com.google.android.gms.auth.api.signin.GoogleSignInOptions;
导入com.google.android.gms.common.SignInButton;
导入com.google.android.gms.common.api.ApiException;
导入com.google.android.gms.tasks.OnCompleteListener;
导入com.google.android.gms.tasks.Task;
/**
*演示谷歌用户ID、电子邮件地址和基本信息的基本检索的活动
*个人资料。
*/
公共类的重要性扩展了AppCompatActivity实现
View.OnClickListener{
私有静态最终字符串标记=“符号活动”;
专用静态最终输入RC\U符号\U IN=9001;
私人谷歌签名客户端mGoogleSignInClient;
私有文本视图mStatusTextView;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u main\u DEMO);
//观点
mStatusTextView=findviewbyd(R.id.status);
//按钮侦听器
findviewbyd(R.id.sign_in_按钮);
findviewbyd(R.id.sign\u out\u按钮);
findviewbyd(R.id.disconnect_按钮);
//[开始配置\登录]
//配置登录以请求用户ID、电子邮件地址和基本信息
//配置文件。ID和基本配置文件包含在默认登录中。
GoogleSignenOptions gso=新建GoogleSignenOptions.Builder(GoogleSignenOptions.DEFAULT\u登录)
.requestEmail()
.build();
//[结束配置\登录]
//[启动构建客户端]
//使用gso指定的选项构建GoogleSignInClient。
mGoogleSignInClient=GoogleSignIn.getClient(this,gso);
//[最终构建客户机]
//[启动自定义按钮]
//设置“登录”按钮的尺寸。
SignInButton SignInButton=findViewById(R.id.sign_in_按钮);
signInButton.setSize(signInButton.SIZE_标准);
设置颜色方案(signInButton.C
package com.google.samples.quickstart.signin;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
/**
* Activity to demonstrate basic retrieval of the Google user's ID, email address, and basic
* profile.
*/
public class SignInActivity extends AppCompatActivity implements
View.OnClickListener {
private static final String TAG = "SignInActivity";
private static final int RC_SIGN_IN = 9001;
private GoogleSignInClient mGoogleSignInClient;
private TextView mStatusTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_DEMO);
// Views
mStatusTextView = findViewById(R.id.status);
// Button listeners
findViewById(R.id.sign_in_button).setOnClickListener(this);
findViewById(R.id.sign_out_button).setOnClickListener(this);
findViewById(R.id.disconnect_button).setOnClickListener(this);
// [START configure_signin]
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
// [END configure_signin]
// [START build_client]
// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
// [END build_client]
// [START customize_button]
// Set the dimensions of the sign-in button.
SignInButton signInButton = findViewById(R.id.sign_in_button);
signInButton.setSize(SignInButton.SIZE_STANDARD);
signInButton.setColorScheme(SignInButton.COLOR_LIGHT);
// [END customize_button]
}
@Override
public void onStart() {
super.onStart();
// [START on_start_sign_in]
// Check for existing Google Sign In account, if the user is already signed in
// the GoogleSignInAccount will be non-null.
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
updateUI(account);
// [END on_start_sign_in]
}
// [START onActivityResult]
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
// [END onActivityResult]
// [START handleSignInResult]
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
// Signed in successfully, show authenticated UI.
updateUI(account);
} catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
updateUI(null);
}
}
// [END handleSignInResult]
// [START signIn]
private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
/* Intent sign = mGoogleSignInClient.getSignInIntent ();
startActivityForResult ( sign, RC_SIGN_IN );*/
}
// [END signIn]
// [START signOut]
private void signOut() {
mGoogleSignInClient.signOut()
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
// [START_EXCLUDE]
updateUI(null);
// [END_EXCLUDE]
}
});
}
// [END signOut]
// [START revokeAccess]
private void revokeAccess() {
mGoogleSignInClient.revokeAccess()
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
// [START_EXCLUDE]
updateUI(null);
// [END_EXCLUDE]
}
});
}
// [END revokeAccess]
private void updateUI(@Nullable GoogleSignInAccount account) {
if (account != null) {
mStatusTextView.setText(getString(R.string.signed_in_fmt, account.getDisplayName()));
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE);
} else {
mStatusTextView.setText(R.string.signed_out);
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE);
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
signIn();
break;
case R.id.sign_out_button:
signOut();
break;
case R.id.disconnect_button:
revokeAccess();
break;
}
}
}