Google SignIn API异常10
接近认证的最后阶段,但是handleSignInResult
方法出了点问题。它在日志中返回异常代码10(开发人员错误)。Google提供了全面的描述:
应用程序配置错误。该错误不可恢复,将被视为致命错误。开发者是个白痴…
我该怎么办(获取帐户)并最终从帐户中检索值?
预先感谢您的帮助!!!
主要活动:
package ru.podgorny.carcall;import ...
public class MainActivity extends AppCompatActivity {
SignInButton signInButton;
public static final int RC_SIGN_IN = 07;
public static final String TAG = "MainActivity";
TextView tw1;
TextView tw2;
GoogleSignInOptions gso;
GoogleSignInClient mGSC;
@Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "Activity Works");
findViews();
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
//.requestProfile()
.build();
mGSC = GoogleSignIn.getClient(this, gso); //smth with mGSC variable....
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
onClick2(v);
}
};
signInButton.setOnClickListener(onClickListener);
}
private void findViews() {
Log.d (TAG, "findViews started");
signInButton = findViewById(R.id.idButtonGoogle);
tw1 = findViewById(R.id.textView1);
tw1 = findViewById(R.id.textView2);
Log.d(TAG, "Views finded");
}
public void onClick2(View view) {
Log.d(TAG, "onClick started");
switch (view.getId()) {
case R.id.idButtonGoogle:
signIn();
break;
}
Log.d(TAG, "OnClick Started");
}
public void signIn() {
Intent signInIntent = mGSC.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
Log.d(TAG, "startActivityForResult works");
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "OnActivityResult started");
// 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.
Log.d(TAG, "TASK started");
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
Log.d(TAG, "OnActivityResult returned");
}
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);//ERROR -- Code 10
Log.d(TAG, "Account received");
updateUI(account);
Log.d(TAG, "updateUI Launched");
} catch (ApiException e) {
Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
updateUI(null);
}
}
private void updateUI(GoogleSignInAccount account) {
if (account!=null) {
tw1.setText("OK");
tw2.setText("Name: " + account.getGivenName() + ", Family name: " + account.getFamilyName() + ", Email: " + account.getEmail() /*+ " image: " +
account.getPhotoUrl()*/);
}else {
tw1.setText("SMTH wrong");
}
}
}
回答:
如果您不在 和
使用同一项目,则可能会发生此错误。如果两个控制台上的项目相同,请确保已正确添加 密钥。从Android Studio 获取
。
- 开启Android Studio
- 打开你的项目
- 单击Gradle(在右侧面板中,您将看到Gradle Bar)
- 单击刷新(在Gradle Bar中单击Refresh,您将看到列出项目的Gradle脚本)
- 单击您的项目(您的项目名称表单列表(根))
- 点击任务
- 点击Android
- 双击signingReport(在运行栏中您将获得SHA1和MD5(有时将在Gradle控制台中))
- 从模块选择下拉列表中选择应用程序模块以运行或调试您的应用程序,还需要从firebase控制台获取google-services.json并将其放入您的项目中。
以上是 Google SignIn API异常10 的全部内容, 来源链接: utcz.com/qa/414038.html