1

大多数 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 使用服务帐户?或有关正确范围字符串的任何信息?

非常感谢。

4

2 回答 2

1

为什么需要为此使用服务帐户?您可以使用常规 OAuth 2.0 授权流程从 Google Apps 超级管理员用户获取授权令牌并使用它:

https://developers.google.com/accounts/docs/OAuth2InstalledApp

于 2012-12-09T21:24:17.123 回答
1

一段时间后,我找到了这个线程,以及文档中最重要的部分。发帖以免其他人在未来浪费时间。

Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported. If your application uses Google Sign-In, some aspects of authorization are handled for you.

请参阅文档的“关于授权协议”部分

于 2021-01-17T02:36:31.807 回答