在此使用 google-api-java-client page我们可以阅读一些流程。
服务帐户流程与日历 API 配合良好:
GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("[[]]")
.setServiceAccountScopes(CalendarScopes.CALENDAR)
.setServiceAccountPrivateKeyFromP12File(new File("key.p12")).build();
但我们一直:
503 Service Unavailable
{
"code" : 503,
"errors" : [ {
"domain" : "global",
"message" : "Backend Error",
"reason" : "backendError"
} ],
"message" : "Backend Error"
}
如果我们使用GroupssettingsScopes.APPS_GROUPS_SETTINGS
(API 控制台授予对此请求的访问权限)。
我们必须使用接近旧的 2 足 OAuth 1.0a 的机制来管理 GApps 帐户的组。
提前非常感谢
最佳答案
使用 Groups Settings API,您需要模拟 Google Apps 用户。该用户必须是管理员。
此外,我个人注意到最好将服务帐户 ID 提供给 setServiceAccountId()
方法。
这对我有用:
GoogleCredential credential = new GoogleCredential.Builder().setTransport(new NetHttpTransport())
.setJsonFactory(new GsonFactory())
.setServiceAccountId("516444413363-4i0cvva2abc8a3t63bbq1a9rfqe42p70@developer.gserviceaccount.com")
.setServiceAccountScopes(Collections.singletonList("https://www.googleapis.com/auth/apps.groups.settings"))
.setServiceAccountUser("admin@my.doma.in")
.setServiceAccountPrivateKeyFromP12File(new File("key.p12")).build();
关于java - 如何将服务帐户 OAuth 2.0 流程与 GroupsSettings-api 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11410942/