android - GoogleSignInResult 在生产中返回 null GoogleSignInAccount
问题描述
我正在关注此将谷歌身份验证集成到我的应用程序中。它在调试 apk 中运行良好,但在发布时,每次都失败。
我已经在云平台上注册了 debug 和 relese SHA-1 密钥。
供参考的代码片段-
private void someMethid(){
String languageURL = "https://www.googleapis.com/auth/profile.language.read";
String genderURL = "https://www.googleapis.com/auth/user.gender.read";
String birthdayURL = "https://www.googleapis.com/auth/user.birthday.read";
GoogleSignInOptions option = new
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestScopes(
new Scope(languageURL),
new Scope(genderURL),
new Scope(birthdayURL)
)
.build();
client = GoogleSignIn.getClient(this, option);
signIn();
}
private void signIn() {
Intent signInIntent = client.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@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) {
GoogleSignInAccount acct = null;
try {
acct = completedTask.getResult(ApiException.class);
if (acct != null) {
fetchData(acct);
}
else {
showDialogMessage("Email verification failed", "failed to get Google account information", false);
client.revokeAccess();
client.signOut();
}
} catch (ApiException e) {
e.printStackTrace();
showDialogMessage("Email verification failed", "failed to get Google account information", false);
client.revokeAccess();
client.signOut();
}
登录提示打开,确实要求提供 google 帐户,但不要求提供所请求范围的权限,并为 GoogleSignInAccount 返回 null。
解决方案
当您说When released
时,您的意思是当您从 Google Play 安装应用程序时?如果您使用的是“Play App Signing”,则需要从 Google Play 控制台添加签名密钥,而不是从您的存储库/密钥库。这是因为 Google Play 代表您签署了该应用程序。
诊断您的问题:看起来应用程序是使用与身份验证服务所期望的密钥不同的密钥签名的,因此服务拒绝了它。它是在你知道的情况下辞职的。
https://support.google.com/googleplay/android-developer/answer/9842756?hl=en
如果这不起作用,请提供更多详细信息:)。如果您需要更多帮助,请告诉我。
推荐阅读
- php - 在特定时间范围内显示数据库实体
- amazon-web-services - amazon emr - 创建集群是否使用数据传出?
- cuda - CUDA:在减和期间计算所有部分和的方法
- google-app-engine - 使用 gcloud app deploy 部署 GAE Flex 时出错
- android - React Native Maps - OnRegionChange 使地图结结巴巴
- angular - 使用 *ngFor 时的两列项目符号列表
- rest - 使用soapUI时监控数据包
- c# - 找不到也无法使用 System.Web.Services.dll
- python - 在 GMail API 中,使用 Python 3,我如何跳到结果的最后一页?
- crystal-reports - Crystal Reports 11:查找数据被过滤掉的位置