【发布时间】:2020-07-16 19:45:40
【问题描述】:
我想以 G Suite 管理员身份通过 Gmail .Net 客户端库更新域用户的签名。
我按照this 示例在谷歌开发者控制台中设置和授予权限。
这是我所做的总结:
- 在 Google API 控制台中启用 Gmail API
- 为我的项目创建了一个服务帐户
- 向服务帐户委派域范围的权限
- 添加了https://www.googleapis.com/auth/gmail.settings.sharing、https://www.googleapis.com/auth/gmail.settings.basic 范围
我可以更新自己的电子邮件签名,但是当我尝试更新域中任何其他用户的签名时,我收到以下错误:
Google.Apis.Requests.RequestError
Not Found [404]
Errors [
Message[Not Found] Location[ - ] Reason[notFound] Domain[global]
]
这是我的代码:
GoogleCredential credential;
using (var stream = new FileStream("signature-gmailapi.json", FileMode.Open, FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream).CreateScoped(new[]
{GmailService.Scope.GmailSettingsBasic, GmailService.Scope.GmailSettingsSharing})
.CreateWithUser("admin@domain.com");
}
var service = new GmailService(new BaseClientService.Initializer()
{
ApplicationName = "Project",
HttpClientInitializer = credential
}
);
service.Users.Settings.SendAs.Patch(new SendAs { Signature = "Test signature..."}, "me",
"user@domain.com").Execute();
谁能指导我做错了什么?
【问题讨论】:
标签: c# gmail-api google-admin-sdk