We are using Google API Client Library(java) to connect to get gmail data using oauth2.
After asking the user to allow the application access to user\'s email the goo