大多数 Google Management API 似乎已为服务帐户启用。例如,我可以像这样检索日历:
string scope = Google.Apis.Calendar.v3.CalendarService.Scopes.Calendar.ToString().ToLower();
string scope_url = "https://www.googleapis.com/auth/" + scope;
string client_id = "999...@developer.gserviceaccount.com";
string key_file = @"\path\to\my-privatekey.p12";
string key_pass = "notasecret";
AuthorizationServerDescription desc = GoogleAuthenticationServer.Description;
X509Certificate2 key = new X509Certificate2(key_file, key_pass, X509KeyStorageFlags.Exportable);
AssertionFlowClient client = new AssertionFlowClient(desc, key) { ServiceAccountId = client_id, Scope = scope_url };
OAuth2Authenticator<AssertionFlowClient> auth = new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);
CalendarService service = new CalendarService(auth);
var x = service.Calendars.Get("calendarID@mydomain.com").Fetch();
但是,GroupssettingsService 上的相同代码返回 503 - 服务器不可用。这是否意味着服务帐户不能与该 API 一起使用?
在一个可能相关的问题中,组设置服务的范围似乎是,apps.groups.settings
但是如果您致电
GroupssettingsService.Scopes.AppsGroupsSettings.ToString().ToLower();
...你得到appsgroupssettings
了,没有嵌入的句点。
是否有另一种方法可以为 GroupssettingsService 使用服务帐户?或有关正确范围字符串的任何信息?
非常感谢。