Aar*_*ron 84 android google-signin
我正在尝试将Google登录集成到我的应用中.我没有后端服务器,我只是将登录的Google帐户的详细信息提供给我的应用程序.
我首先尝试使用Google登录示例,但是我收到了一个错误(除了打印下面的堆栈跟踪之外,没有更改代码).我只使用了示例SignInActivity,因为我没有后端服务器.
Exception com.google.android.gms.common.api.ApiException: 12500:
at com.google.android.gms.common.internal.zzb.zzz(Unknown Source)
at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(Unknown Source)
at com.ewise.android.api.MainActivity.onActivityResult(SignInActivity.java:89) at android.app.Activity.dispatchActivityResult(Activity.java:7010)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4187)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4234)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1584)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6316)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Run Code Online (Sandbox Code Playgroud)
码
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);
// 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());
e.printStackTrace();
updateUI(null);
}
}
// [END handleSignInResult]
// [START signIn]
private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, 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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
从我读到的,问题可能是由SHA1 Generation引起的.
我按照完整的指南,但显然它不起作用.
我从gradle signingReport复制了SHA1
Variant: debug
Config: debug
Store: /Users/user/.android/debug.keystore
Alias: AndroidDebugKey
MD5: A3:16:3F:43:75:FE:07:62:6D:8D:CC:DD:21:9F:FA:1A
SHA1: 7B:21:26:7F:D8:18:BB:0E:36:1C:82:DD:B7:28:5F:C1:2F:5C:E4:EA
Valid until: Saturday, August 31, 2047
----------
Variant: release
Config: none
----------
Variant: debugAndroidTest
Config: debug
Store: /Users/user/.android/debug.keystore
Alias: AndroidDebugKey
MD5: A3:16:3F:43:75:FE:07:62:6D:8D:CC:DD:21:9F:FA:1A
SHA1: 7B:21:26:7F:D8:18:BB:0E:36:1C:82:DD:B7:28:5F:C1:2F:5C:E4:EA
Valid until: Saturday, August 31, 2047
----------
Variant: debugUnitTest
Config: debug
Store: /Users/user/.android/debug.keystore
Alias: AndroidDebugKey
MD5: A3:16:3F:43:75:FE:07:62:6D:8D:CC:DD:21:9F:FA:1A
SHA1: 7B:21:26:7F:D8:18:BB:0E:36:1C:82:DD:B7:28:5F:C1:2F:5C:E4:EA
Valid until: Saturday, August 31, 2047
Run Code Online (Sandbox Code Playgroud)
可能的原因是什么?
谢谢
PS这可能是一个可能的原因吗?
Google Play services out of date. Requires 11720000 but found 10932470
Run Code Online (Sandbox Code Playgroud)
Mad*_*oop 56
错误PlatformException(sign_in_failed,com.google.android.gms.common.api.ApiException:12500:,null)
通过 在项目设置中向项目添加支持电子邮件地址,可以解决此12500错误。 打开链接 https://console.firebase.google.com/
选择您的项目并打开设置选项卡。
提供有效的支持电子邮件并立即重新启动您的应用程序。
Niy*_*zar 39
检查是否将SHA-1指纹添加到firebase项目设置中.如果没有,请使用找到SHA-1指纹
https://developers.google.com/android/guides/client-auth
另外,使用找到释放密钥的SHA-1指纹
keytool -list -v -keystore <keystore path>
Run Code Online (Sandbox Code Playgroud)
<keystore path>使用密钥库的路径删除.
然后将两个SHA-1指纹添加到firebase项目设置中.
注意:不要忘记用更新的指纹替换google-services.json和更新的google-services.json.我失去了两天.
Android studio会在第一次调试构建时自动生成 并使用它来签署应用程序.~/.android/debug.keystore
要获得SHA-1运行(密码android)(doc):
keytool -exportcert -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore
Run Code Online (Sandbox Code Playgroud)
这SHA-1应该添加到应用程序设置中,firebase以允许在测试调试版本时使用谷歌登录功能.
Str*_*uss 32
只需将您的Google Play服务更新为最新版本(在本例中为11720000).如果您使用AVD,Nexus 5和5X图像支持Google Play.模拟器启动并运行后,转到扩展控件菜单> Google Play,然后更新.
zub*_*b0r 29
支持电子邮件以及所有项目和隐私链接对于Google SignIn来说是必需的,否则将抛出12500。
在https://console.developers.google.com/apis/credentials上进行设置
Firebase指南中没有任何提及。
Fau*_*tha 18
尝试更新https://console.developers.google.com/apis/credentials上的OAuth同意屏幕
小智 10
似乎您的SHA1被Google Play商店覆盖.检查您的Google Play商店,启动面板,在应用签名下,查看Google Play是否添加了额外的SHA1.
并复制SHA1,添加到您的相关位置,将完成这项工作.
Ree*_*eed 10
就我而言,问题是我的模拟器没有 Play 商店。我通过 Visual Studio 制作了模拟器(名为 API 23),因为我也使用 Xamarin.Forms 进行开发,并且在 Visual Studio 的 Android 设备管理器中,您可以选择模拟器是否应该具有 Google Play 商店。
必须通过 Android Studio 的 AVD 创建模拟器并确保它有 Play Store:
就我而言,出现此错误是因为高级团队删除了 android 身份验证,因为后端身份验证中似乎不需要 android 密钥。所以google登录时需要Android和Web客户端密钥。
小智 5
我认为错误来自错误的 SHA1。请不要忘记,android studio 中发布和调试模式的 SHA1 是不同的。除了使用 keytool 获取 SHA1,您可以在 android studio 中使用 Gradle 项目 -> 任务 -> android -> 签名报告(可以通过菜单 View -> Toolwindow -> gradle 打开)来获取发布和调试 SHA1。之后,为了方便工作,您需要在 google 云控制台上创建 2 个单独的凭证和两个 SHA1(谷歌只是指示使用发布 SHA1 创建 1,当我们开发它时它不会工作,因为它使用调试 SHA1)。
小智 5
在 Firebase 控制台中转到您的项目,打开项目设置,在那里添加您的 SHA 证书指纹。下载更新的 google-services.json 文件并将其添加到您的 Projects 应用文件夹。
这对我有用。
我正在使用Firebase身份验证。正确指示了我的SHA-1,客户端ID也正确,但是我仍然得到12500。
原来,我的问题是我没有在项目设置中指出支持电子邮件。(设置->常规标签->您的项目(公共设置)部分)。
| 归档时间: |
|
| 查看次数: |
55230 次 |
| 最近记录: |