java - GoogleSignIn.getLastSignedInAccount() 返回具有空字段的帐户

标签 java android google-signin

我正在我的项目中实现 Google Sign-in,但这个问题很难。当我没有签名时,GoogleSignIn.getLastSignedInAccount(activity) 返回 null,根据 Google's documentation,这是它应该做的。 .当我重新启动应用程序时,它返回一个 GoogleSignInAccount,但所有字段都为 null

谷歌说:

For additional profile data that might be available, see GoogleSignInAccount. Note that any of the profile fields can be null, depending on which scopes you requested and what information the user's profile includes.

所以我认为问题是缺少请求的信息,但我之前正确地定义了它们:

GoogleSignIn.getClient(activity, GoogleSignInOptions.Builder()
    .requestId()
    .requestProfile()
    .requestEmail()
    .build()
);

此外,在使用上述相同的客户端请求注册后,所有信息都在一个完美的 GoogleSignInAccount 中。

最佳答案

在我的游戏中,当 GoogleSignIn.getLastSignedInAccount(activity) 返回 null 时,我调用 开始登录 Intent :

private void startSignInIntent() {
  GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
      GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
  Intent intent = signInClient.getSignInIntent();
  startActivityForResult(intent, RC_SIGN_IN);
}

关于java - GoogleSignIn.getLastSignedInAccount() 返回具有空字段的帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48293027/

相关文章:

java - 比较时得到 “Illegal generic type for instanceof”错误

android - GoogleSignInAccount 返回 null

swift - 如何使用 google 登录 sdk 在 UIButton 而不是 UIView 中实现 google 登录?

java - Admob 横幅广告未在 Android 4.4 (KITKAT) 中显示,但在更高的 API 级别下运行良好

android - 如何在设备中调试我的 android 应用程序

java - 如何连接到远程HDFS

Android 应用程序 - 在 Google Play 上未找到 native 库错误报告?

node.js - 尝试用身份验证代码换取凭证时出现unauthorized_client

java - HttpServlet 类与 Jersey 的混淆

说明 amazon dynamodb 用法的 java 代码示例