我成功地使用服务帐户获得域范围的权限来访问用户的驱动器文件和日历,如下所示:
ServiceAccountCredential.Initializer initializer =
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = serviceAccountScope,
User = "user1@myDomain.com"
}.FromCertificate(certificate);
ServiceAccountCredential credential = new ServiceAccountCredential(initializer);
service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = appName,
});
但是,我并不完全确定更改用户的最佳方式,尤其是当我同时与许多用户打交道时。是否最好重新开始并为每个用户创建一个新的初始化程序和服务?或者是否可以保持相同的服务并只更新被模仿的用户?