Google Email Settings api using OAuth 2.0 service account in java

半城伤御伤魂 提交于 2020-01-06 14:55:17

问题


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/



来源:https://stackoverflow.com/questions/28321745/google-email-settings-api-using-oauth-2-0-service-account-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!