这是我从 Google Developers 页面获取的代码
signInRequest = BeginSignInRequest.builder()
.setPasswordRequestOptions(BeginSignInRequest.PasswordRequestOptions.builder()
.setSupported(true)
.build())
.setGoogleIdTokenRequestOptions(BeginSignInRequest.GoogleIdTokenRequestOptions.builder()
.setSupported(true)
// Your server's client ID, not your Android client ID.
.setServerClientId(getString(R.string.server_id))
// Only show accounts previously used to sign in.
.setFilterByAuthorizedAccounts(true)
.build())
.build();
oneTapClient.beginSignIn(signInRequest)
.addOnSuccessListener(this, new OnSuccessListener<BeginSignInResult>() {
@Override
public void onSuccess(BeginSignInResult result) {
try {
startIntentSenderForResult(
result.getPendingIntent().getIntentSender(), REQ_ONE_TAP, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "Couldn't start One Tap UI: " + e.getLocalizedMessage());
}
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// No saved credentials found. Launch the One Tap sign-up flow, or
// do nothing and continue presenting the signed-out UI.
Log.d(TAG, e.getLocalizedMessage());
}
});
我正在 Android 应用程序中实现一键登录和注册,并且我还在 Google API 控制台中创建了一个项目,并在此处提到了客户端 ID,但上述代码不起作用。
我已经搜索了示例项目,但不可用,并且也没有用于逐步代码流程的示例 YouTube 视频。接下来我可以尝试什么?
最佳答案
日志会有帮助,尽管我猜这是异常(exception):
No matching credentials found
在代码更改
.setFilterByAuthorizedAccounts(true)
至
.setFilterByAuthorizedAccounts(false)
关于java - 如何在 Android 中进行一键登录和注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62933351/