我想以Gmail管理员身份通过Gmail .Net客户端库更新域用户的签名。
我按照this示例在Google开发人员控制台中进行设置和授予权限。
这是我所做的摘要:
我能够更新自己的电子邮件签名,但是当我尝试更新域中任何其他用户的签名时,出现以下错误:
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("[email protected]");
}
var service = new GmailService(new BaseClientService.Initializer()
{
ApplicationName = "Project",
HttpClientInitializer = credential
}
);
service.Users.Settings.SendAs.Patch(new SendAs { Signature = "Test signature..."}, "me",
"[email protected]").Execute();
任何人都可以指导我做错了什么吗?
这通过方法CreateWithUser();
实现
您需要分配给它的参数是用户的电子邮件,而不是管理员的电子邮件。因此:
credential = GoogleCredential.FromStream(stream).CreateScoped(new[]{GmailService.Scope.GmailSettingsBasic, GmailService.Scope.GmailSettingsSharing})
.CreateWithUser( "[email protected]");