java - 无法登录 Google 帐户 登录失败
问题描述
我已经在我的应用程序中创建了 Google 和 Facebook 登录但我无法通过它显示的 Google 帐户登录SignIn failed
。
我已经看到它没有显示错误的代码,应用程序也没有崩溃,但我无法通过谷歌登录。我尝试了许多不同的谷歌账户,但每次它显示“登录失败”。
private void signIn() {
if (checkPermission()) {
if (UtilityMethods.isInternetAvailable(mContext)) {
new GetQuestionOfTheDay(mContext).execute();
new GetQuickTen(mContext).execute();
loginType = "Google";
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
} else {
UtilityMethods
.showAlert(mContext, "No Internet Connection",
"Please enable internet connection to login.",
"Ok");
}
} else {
requestPermission(ChoiceActivity.this);
}
}
private void fbSignIn() {
if (checkPermission()) {
if (UtilityMethods.isInternetAvailable(mContext)) {
new GetQuestionOfTheDay(mContext).execute();
new GetQuickTen(mContext).execute();
loginType = "Facebook";
loginButton.performClick();
} else {
UtilityMethods
.showAlert(mContext, "No Internet Connection",
"Please enable internet connection to login.",
"Ok");
}
} else {
requestPermission(ChoiceActivity.this);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent
data) {
callbackManager.onActivityResult(requestCode, resultCode, 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);
}
}
private void handleSignInResult(Task<GoogleSignInAccount>
completedTask) {
try {
GoogleSignInAccount account =
completedTask.getResult(ApiException.class);
displayName = account.getDisplayName();
socialMailId = account.getEmail();
new Registration().execute();
} catch (ApiException e) {
// The ApiException status code indicates the detailed failure
reason.
// Please refer to the GoogleSignInStatusCodes class reference
for more information.
AppUtil.log(TAG, "signInResult:failed code=" + e.getStatusCode(),
e);
Toast.makeText(mContext, "SignIn Failed ...",
Toast.LENGTH_SHORT).show();
databaseHandler.flushQuickTenData();
// updateUI(null);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull
String[] permissions,
@NonNull int[] grantResults) {
switch (requestCode) {
case MY_REQUEST: {
if (grantResults.length > 0) {
boolean isReadExternalStoragePermission = grantResults[0]
== PackageManager.PERMISSION_GRANTED;
boolean isWriteExternalStoragePermission =
grantResults[1] == PackageManager.PERMISSION_GRANTED;
if (isReadExternalStoragePermission &&
isWriteExternalStoragePermission) {
Toast.makeText(ChoiceActivity.this, "All Permission
Granted", Toast.LENGTH_SHORT).show();
isAccess = true;
} else {
isAccess = false;
int i = 0;
StringBuilder stringBuilder = new StringBuilder();
if (isReadExternalStoragePermission &&
isWriteExternalStoragePermission) {
if (i == 1) {
stringBuilder.append(", Storage");
} else {
stringBuilder.append("Storage");
}
}
Toast.makeText(ChoiceActivity.this,
stringBuilder.toString() + " Permission Denied",
Toast.LENGTH_SHORT).show();
}
}
break;
}
}
}
我尝试调试应用程序,所以当我按下谷歌中的帐户按钮时,它会在我的调试器中显示此错误。
E/ChoiceActivity: signInResult:failed code=10
com.google.android.gms.common.api.ApiException: 10: at
com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus
(UnknownSource) at
com.google.android.gms.auth.api.signin.GoogleSignIn.
getSignedInAccountFromIntent(Unknown Source)
at com.taxsmart.activity.ChoiceActivity.onActivityResult
(ChoiceActivity.java:284)
at android.app.Activity.dispatchActivityResult(Activity.java:6461)
at android.app.ActivityThread.deliverResults
(ActivityThread.java:3960)
at android.app.ActivityThread.handleSendResult
(ActivityThread.java:4007)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage
(ActivityThread.java:1551)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5763)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)"
解决方案
推荐阅读
- regex - 正则表达式替换谷歌表替换多个数字
- heroku - Heroku 模型部署成功,但未找到 nltk.txt
- python - 棘手的python控制流
- reactjs - 使用 react-multi-carousel 为不同设备自定义转换
- loopback - 删除“id”字段作为默认排序选项
- firebase - 调试实时应用程序的实时数据库安全规则
- excel - 仅在粘贴到 Excel 时粘贴值
- java - keyExists 无法解析为变量 - Java
- biztalk - BizTalk 中同一终结点上收到的两方的路由消息
- android - 阻止 Android Studio Gradle 构建使用互联网数据的方法