Android: GoogleAuthUtil.getToken - 帐户对象应该来自哪里?

Android: GoogleAuthUtil.getToken - where is the account object supposed to come from?

GoogleAuthUtil.getToken 的第二个参数需要一个帐户对象,但是当您使用 Google SignIn 连接时,您得到的结果是 GoogleSignInAccount - 这不是同一件事情。有没有办法将 GoogleSignInAccount 转换为帐户对象?

 private void handleSignInResult(GoogleSignInResult result) {

        if (result.isSuccess()) {

            googleSignInAccount = result.getSignInAccount();

        }
    }

然后稍后:

authToken = GoogleAuthUtil.getToken(context, [need an account here], scope);

我知道我可以通过显示帐户选择器取回电子邮件地址,我也可以从 google 登录结果中获取电子邮件地址 - 但我看不到获取整个的方法帐户对象。

使用文档here you can see that the response has KEY_ACCOUNT_NAME and KEY_ACCOUNT_TYPE. Therefore you can create your own Account object

代码:

  if (requestCode == REQUEST_CODE_PICK_ACCOUNT) {
            // Receiving a result from the AccountPicker
            if (resultCode == RESULT_OK) {
                mEmail = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
                mType = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
                // With the account name acquired, go get the auth token
                Account account = new Account(mEmail, mType);
                String token =  GoogleAuthUtil.getToken(context, account, mScope);
            }