4

I was implementing google sign but i came to this method and this is deprecated show its always return null value

String  token = GoogleAuthUtil.getToken(loginActivity, accountName, scopes);

even i used other methods

 String token = GoogleAuthUtil.getToken(loginActivity, accountName, scopes, null);

but it still returns null and shows as it is deprecated. Please help how can i get access token

FaisalAhmed
  • 3,469
  • 7
  • 46
  • 76
  • for now you can use compile('com.google.android.gms:play-services:6.5.+@aar') , it supports this method. – Usman Rana Jan 09 '17 at 13:16
  • Possible duplicate of [Should I use GoogleAuthUtil.getToken(...) or not?](http://stackoverflow.com/questions/40069681/should-i-use-googleauthutil-gettoken-or-not) – Linda Lawton - DaImTo Jan 09 '17 at 13:17

1 Answers1

6

In the below getToken method, I think you are passing accountName which is a string value.

String  token = GoogleAuthUtil.getToken(loginActivity, accountName, scopes);
String token = GoogleAuthUtil.getToken(loginActivity, accountName, scopes, null);

thus it will still return deprecated method getToken.

converting string into account before passing as mentioned below will help`:

Account accountDetails = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);

String  token = GoogleAuthUtil.getToken(loginActivity, accountDetails, scopes);

Hope this helps.

Bhargavaroyal
  • 69
  • 1
  • 5