How to get user id from authencicated credential

Keywords: google-oauth2


How can I get the id or email of user from the authenticated credential?

I use the sample code like this:

InputStream in = GmailReplyService.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
if (in == null) {
    throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
            .setDataStoreFactory(new FileDataStoreFactory(new

I can authenticate my app in the browser , and I want to know the user unique id from the result. The class Credential did not give the user id to get, it only return the access token. I do not know how to transform between them . I want to save the user token into my database, and I need the unique id. Is there anyone can help me, thanks a lot.