【问题标题】:Google Email Settings api using OAuth 2.0 service account in java在 Java 中使用 OAuth 2.0 服务帐户的 Google 电子邮件设置 api
【发布时间】:2015-04-03 23:55:07
【问题描述】:
我想使用 Java 中的 OAuth2.0 服务帐户身份验证方法使用 Google 电子邮件设置 api,但是我无法从 Google 找到任何有用的客户端类或有关如何执行此操作的示例示例。我查看了对用户或组相关操作非常有用的 Directory api。电子邮件设置 api 有没有等价物?
【问题讨论】:
标签:
java
google-admin-sdk
service-accounts
google-email-settings-api
google-oauth
【解决方案1】:
您仍然可以将旧库 AppsForYourDomainClient.jar 与服务帐户一起使用。您需要覆盖使用用户/密码的方法并设置您的 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);