-2

I'm developing an app which has an Button in login page to log to the app using the Google account. and i need the access token which will return after a success login. can any one help me please...

2 Answers2

1

You might want to authenticate the user using one of the google account already configured in your device like some of the apps do, for that follow the below link -

"Authenticating to OAuth2 Services" - link Download Sample from Google - Android SDK Manager/Extras/Google Play Services

In simple steps it does

Shows list of accounts in your mobile Generates access token from selected accounts Gets the Account name from access token by contacting google services(seperate call) to just tell that it has authenticated. This is another link which is good in explaining the process link you can follow below steps for Login in your app

you will send the generated access token to your Back-end server Back-end server checks that access token is valid or not by contacting google services by this url

Next Back-end server responds to app whether to make the user login or not. Below is response format of above "userinfo" call

you 'll get response as below

{
 "id": "ID",
 "name": "NAME",
 "given_name": "GiVEN NAME",
 "family_name": "FAMILY_NAME",
 "link": "https://plus.google.com/ID",
 "picture": "https://PHOTO.jpg",
 "gender": "GENDER",
 "locale": "LOCALE"
}

If you want Email id along with that response you have to modify

SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile";

to

SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email";

in that sample.

source

Community
  • 1
  • 1
kathir
  • 489
  • 2
  • 11
1

You will get all the google accounts which are synchronized with your mobile

AccountManager accountManager = AccountManager.get(YourActivity.this);
    Account[] accountsByType = accountManager
            .getAccountsByType("com.google");

check this, this is helpful to you,

Note dont forgot to add the permissions

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
Jagadesh Seeram
  • 2,630
  • 1
  • 16
  • 29