我一直在开发一个工具,稍后将用于管理组织中的用户签名,我已经成功地完成了所有的应用程序,在测试期间我发现我只能更改我的签名。。。
我认为问题在于权限和授权。我使用的是OAuth客户端ID,我在控制台上创建了这个项目。开发者。谷歌。com和我启用了Gmail API。
下面是我代码的重要部分:
public async void btnAuthorize_Click(object sender, EventArgs e)
{
try
{
updateOutput("Trying to authorize with Google", "I");
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { GmailService.Scope.GmailSettingsBasic }, "user"
, CancellationToken.None, new FileDataStore("Gmail.Signature"));
}
updateOutput("Authorized successfully", "I");
btnUpdateSignature.Enabled = true;
}
catch (Google.GoogleApiException ex)
{
updateOutput(ex.Message, "E");
}
}
private void btnUpdateSignature_Click(object sender, EventArgs e)
{
// reading the users list one by one
// reading the signature text
// replacing the place holders with actual values
// upload the real signature text
// Create the service.
string signatureLocal = "";
string[] dataFields;
string userEmail;
int position=0;
string stat = "";
try
{
if (csvData_Arr.Length > 0)
{
foreach (string line in csvData_Arr)
{
if (position==0)
{
// skip this step, this is the header
position++;
}
else
{
dataFields = line.Split(',');
userEmail = dataFields[0];
signatureLocal = mapSignatureFields(signatureText, dataFields);
updateOutput("Updating signature for: " + userEmail, "I");
stat = updateSignature(userEmail, signatureLocal);
updateOutput(stat, "D");
if (chkGetbackSig.Checked == true)
{
updateOutput("Final signature: " + signatureLocal, "I");
}
position++;
}
}
}
}
catch (Exception ex)
{
updateOutput(ex.Message, "E");
}
}
private string updateSignature(string emailID, string signatureText)
{
SendAs sendAsObj = new SendAs();
service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Gmail API - Signature Manager",
});
try
{
sendAsObj.SendAsEmail = emailID;
sendAsObj.Signature = signatureText;
service.Users.Settings.SendAs.Patch(sendAsObj, emailID, emailID).Execute();
UsersResource.SettingsResource.SendAsResource.GetRequest sendAsRes = service.Users.Settings.SendAs.Get(emailID, emailID);
if (chkGetbackSig.Checked==true)
{
return sendAsRes.Execute().Signature.ToString();
}
return "";
}
catch (Google.GoogleApiException ex)
{
return ex.Message;
}
}
在执行应用程序时,它可以成功更新我的签名,但对于其他用户,它会返回以下信息:
谷歌。API。请求。RequestError拒绝请求/委派中指定的无效用户id[403]错误[消息[拒绝请求/委派中指定的无效用户id]位置[-]原因[禁止]域[全局]]
我有点迷茫,不知道应该在哪里以及如何让它与其他用户一起工作。创建项目时使用的帐户在域上具有超级管理员权限。
谢谢你的帮助
编辑1:我尝试使用服务号,但我似乎做错了:
private async void button1_Click(object sender, EventArgs e)
{
string signatureLocal = "";
string[] dataFields;
string userEmail;
int position = 0;
string stat = "";
string certPath=appPath + "saKey.p12";
var cert = new X509Certificate2(certPath, "notasecret", X509KeyStorageFlags.Exportable);
string[] scopes = new string[] {GmailService.Scope.GmailSettingsBasic};
try
{
updateOutput("Trying to authorize with Google", "I");
ServiceAccountCredential cred = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer("xxx@cool-monolith-153015.iam.gserviceaccount.com")
{
Scopes = scopes
}.FromCertificate(cert));
serviceSA = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = cred,
ApplicationName = "Gmail API - Signature Manager",
});
updateOutput("Authorized successfully", "I");
SendAs sendAsObj = new SendAs();
foreach (string line in csvData_Arr)
{
if (position == 0)
{
// skip this step, this is the header
position++;
}
else
{
dataFields = line.Split(',');
userEmail = dataFields[0];
signatureLocal = mapSignatureFields(signatureText, dataFields);
updateOutput("Updating signature for: " + userEmail, "I");
sendAsObj.SendAsEmail = userEmail;
sendAsObj.Signature = signatureLocal;
serviceSA.Users.Settings.SendAs.Patch(sendAsObj, userEmail, userEmail).Execute();
UsersResource.SettingsResource.SendAsResource.GetRequest sendAsRes = serviceSA.Users.Settings.SendAs.Get(userEmail, userEmail);
if (chkGetbackSig.Checked == true)
{
updateOutput(sendAsRes.Execute().Signature.ToString(), "D");
}
updateOutput(stat, "D");
if (chkGetbackSig.Checked == true)
{
updateOutput("Final signature: " + signatureLocal, "I");
}
position++;
}
}
}
catch (Google.GoogleApiException ex)
{
updateOutput(ex.Message, "E");
}
}
我找到了一个有效的代码:
private async void button1_Click(object sender, EventArgs e)
{
string signatureLocal = "";
string[] dataFields;
string userEmail;
int position = 0;
string stat = "";
string certPath=appPath + "saKey.p12";
var cert = new X509Certificate2(certPath, "notasecret", X509KeyStorageFlags.Exportable);
string[] scopes = new string[] {GmailService.Scope.GmailSettingsBasic, GmailService.Scope.MailGoogleCom};
try
{
SendAs sendAsObj = new SendAs();
foreach (string line in csvData_Arr)
{
if (position == 0)
{
// skip this step, this is the header
position++;
}
else
{
dataFields = line.Split(',');
userEmail = dataFields[0];
updateOutput("Trying to authorize with Google", "I");
ServiceAccountCredential cred = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer("xxx@cool-monolith-153015.iam.gserviceaccount.com")
{
User = userEmail,
Scopes = scopes
}.FromCertificate(cert));
updateOutput("Authorized successfully", "I");
serviceSA = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = cred,
ApplicationName = "Gmail API - Signature Manager",
});
signatureLocal = mapSignatureFields(signatureText, dataFields);
updateOutput("Updating signature for: " + userEmail, "I");
sendAsObj.SendAsEmail = userEmail;
sendAsObj.Signature = signatureLocal;
serviceSA.Users.Settings.SendAs.Patch(sendAsObj, userEmail, userEmail).Execute();
UsersResource.SettingsResource.SendAsResource.GetRequest sendAsRes = serviceSA.Users.Settings.SendAs.Get(userEmail, userEmail);
if (chkGetbackSig.Checked == true)
{
updateOutput(sendAsRes.Execute().Signature.ToString(), "D");
}
updateOutput(stat, "D");
if (chkGetbackSig.Checked == true)
{
updateOutput("Final signature: " + signatureLocal, "I");
}
position++;
}
}
}
catch (Google.GoogleApiException ex)
{
updateOutput(ex.Message, "E");
}
}
这里有一个问题,如果我每次迭代都重新验证,可以吗?我可能会每秒钟有1000个账户要验证...
谢谢
我看了这些例子:http://www.jellyfishtechnologies.com/integration-with-google-using-grails-oauth-plugin/ http://www . jelly fish technologies . com/integration-with-Google-using-oauth 2-grails-oauth-plugin/ 我无
我有一个谷歌办公套件电子邮件地址example@gmail.com我创建了一个谷歌服务号example-sa@iam.gserviceaccount.com。 我的目标是从这个SA发送电子邮件,就像它是电子邮件一样,但我无法验证SA。 不过,我可以使用以下代码登录服务帐户Google Drive: 然而,当我尝试为gmail做同样的事情时,我得到了一个错误: 错误: 如果我点击错误消息中提供的UR
我建立Android应用程序链接到谷歌云存储。我想允许访问GCS到我的Android应用程序只。 谷歌提供三种安全连接地面军事系统的解决方案: Oauth 2.0(谷歌账户也是如此) 资料来源:https://developers.google.com/storage/docs/authentication?hl=FR 是否有其他通过地面军事系统安全连接的解决方案?我希望通过这种方式在地面军事系统
所以,在做了一些研究之后,我已经能够拼凑出以下代码,我认为它将在Chrome中执行一个用户-代理切换,然后打开一个新的bing.com页面: 但是,代码似乎不起作用,在打开指定网页之前就停止了。我很确定代码的前半部分是关闭的,但我不太确定是怎么关闭的。我们将非常感谢任何帮助。
我正在制作一个谷歌网站,它显示了基于来自谷歌表的数据的下拉。它工作。 作为下一步,我希望当用户从列表中选择一个下拉选项时,所选的值将写入Google Sheet单元格(在下面的示例中,所选的值将写入Sheet:“Dashboard”,单元格:B92)。 例如,假设下拉列表具有来自工作表的以下值:“项目1”、“项目2”、“项目3”。 当用户从网站上选择“item1”时,脚本应该在googleshee
我试图上传图像文件到我在GCS的桶中,只在我的页面上插入了一个文件输入和一个按钮进行测试,当我点击按钮时,它没有做任何事情,没有错误,什么都没有。我在谷歌云平台计算引擎中使用的是Ubuntu VM。实际上,我无法使用谷歌云存储客户端做任何事情,无法上传对象、列出对象、列出存储桶,我已经将它上传到我的网站,但它不工作,首先在localhost上尝试,但它给了我这个错误:cURL错误60: SSL证书