-->

Google Email Settings api using OAuth 2.0 service

2019-09-03 12:52发布

问题:

I want to use Google Email Settings api using OAuth2.0 service account authentication method in Java, however I am unable to find any useful client classes from Google or sample examples about how to do this. I have had a look at Directory apis which are very useful for user or group related operations. Is there any equivalent for Email Settings api?

回答1:

You can still use the old library AppsForYourDomainClient.jar with Service Accounts. You need to override the method were the user/password are used and set your GoogleCredential:

service = new GmailSettingsService(VERSION_HEADER, getDomain(), null, null) {
@Override
public void setUserCredentials(String username, String password)
        throws AuthenticationException {
    // Nothing to do here.
}};

service.setOAuth2Credentials(saCredential);


回答2:

Google's own library is here: https://github.com/google/google-oauth-java-client, with Maven details if y are using it.

Documentation, with examples, starts here: https://developers.google.com/api-client-library/java/google-oauth-java-client/