10

GoogleAuthUtil.getToken requires for it's second parameter an account object, but when you connect with Google SignIn what you get back in the result is a GoogleSignInAccount - which isn't the same thing. Is there a way to convert the GoogleSignInAccount to an Account object?

 private void handleSignInResult(GoogleSignInResult result) {

        if (result.isSuccess()) {

            googleSignInAccount = result.getSignInAccount();

        }
    }

then later:

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

I know that I can get the email address back by displaying the accountpicker, and I can also get the email address from the google signin result - but I can't see a way to get the entire account object.

Jon
  • 7,273
  • 6
  • 38
  • 99

1 Answers1

7

Using the documentation here you can see that the response has KEY_ACCOUNT_NAME and KEY_ACCOUNT_TYPE. Therefore you can create your own Account object

Code:

  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);
            } 
easycheese
  • 5,579
  • 9
  • 47
  • 83