有人知道Admin SDK / Email Settings API最近是否有变化?以前我们可以为已禁用的用户委派用户帐户,但不再是这种情况。
以下是stacktrace:
400 Bad Request
{
"error" : "invalid_grant"
}. Stacktrace follows:
com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_grant"
}
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:269)
at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)
at com.google.gdata.client.GoogleAuthTokenFactory$OAuth2Token.refreshToken(GoogleAuthTokenFactory.java:258)
at com.google.gdata.client.GoogleAuthTokenFactory.handleSessionExpiredException(GoogleAuthTokenFactory.java:702)
at com.google.gdata.client.GoogleService.handleSessionExpiredException(GoogleService.java:738)
at com.google.gdata.client.GoogleService.insert(GoogleService.java:617)
at com.google.gdata.client.appsforyourdomain.AppsForYourDomainService.insert(AppsForYourDomainService.java:100)
at sample.appsforyourdomain.gmailsettings.OpenDevGmailSettingsService.insertSettings(OpenDevGmailSettingsService.java:182)
at sample.appsforyourdomain.gmailsettings.OpenDevGmailSettingsService.addEmailDelegate(OpenDevGmailSettingsService.java:1073)
at com.opendev.core.GoogleEmailDelegateService.addEmailDelegate(GoogleEmailDelegateService.groovy:76)
at com.opendev.core.EmailDelegateController$_save_closure2_closure3.doCall(EmailDelegateController.groovy:68)
at com.opendev.core.EmailDelegateController$_save_closure2.doCall(EmailDelegateController.groovy:63)
at com.opendev.core.EmailDelegateController.save(EmailDelegateController.groovy:62)
at grails.plugin.multitenant.core.servlet.CurrentTenantServletFilter.doFilter(CurrentTenantServletFilter.java:53)
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53)
at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49)
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:701)
我更新了GmailSettingsService并使用新的构造函数创建了OpenDevGmailSettingsService:
public OpenDevGmailSettingsService(String domain, String serviceAccountId, String serviceAccountUser, String serviceAccountApplicationName, String privateKeyFileLocation) throws AuthenticationException {
super(serviceAccountApplicationName, Constants.PROTOCOL, Constants.APPS_APIS_DOMAIN);
this.domain = domain;
new GenericFeed().declareExtensions(getExtensionProfile());
try {
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
List<String> SCOPES = Arrays
.asList("https://apps-apis.google.com/a/feeds/emailsettings/2.0/");
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(serviceAccountId)
.setServiceAccountUser(serviceAccountUser)
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(
new File(privateKeyFileLocation)).build();
this.setOAuth2Credentials(credential);
} catch (Exception e) {
throw new AuthenticationException(
"Unable to initialize Gmail Settings service" + e);
}
}
此处serviceAccountUser
是当前用户域的admin-user-email-id。