我正在尝试按照https://developers.google.com/identity/sign-in/android/sign-in的指南将Google登录功能集成到我的Android应用中。但是,即使在应用正常运行的情况下,我在“运行”窗口中之前和之后登录时发现以下错误:
“ E / GraphResponse:{HttpStatus:404,错误代码:803,subErrorCode:-1,错误类型:OAuthException,错误消息:(#803)您请求的某些别名不存在:YOUR_APP_ID}”
我不确定根本原因是什么。有人可以帮忙吗?
致谢, 布莱恩
公共类LoginActivity扩展了AppCompatActivity {
private static String TAG = "TAG LoginActivity";
private static final int RC_SIGN_IN = 205;
private GoogleSignInClient mGoogleSignInClient;
private Context context;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
context = getBaseContext();
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "onclick 1");
switch (v.getId()) {
case R.id.sign_in_button:
signIn();
break;
}
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
updateUI(account);
} catch (ApiException e) {
Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
updateUI(null);
}
}
private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
protected void onStart() {
super.onStart();
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
updateUI(account);
}
private void updateUI(GoogleSignInAccount account) {
if (account != null) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
} else {
Toast.makeText(context, "Login failed", Toast.LENGTH_SHORT);
}
}