Google API(Gmail)失败,前提条件失败400

问题描述 投票:2回答:1

我正在尝试使用谷歌API阅读电子邮件,我一再未能取得好成绩。它应该是在后台定期运行的服务器 - >服务器帐户,但我无法连接它。代码是基本的:

GoogleCredential credential;
using (var stream = new FileStream("Content/service_credential.json", FileMode.Open, 
                                   FileAccess.Read))
{
    credential = GoogleCredential.FromStream(stream);
    credential = credential.CreateScoped(new[] { GmailService.Scope.GmailModify });
}

var service = new GmailService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "try-apis",
});


ListLabelsResponse response = service.Users.Labels.List("me").Execute();
foreach (Label label in response.Labels.OrderBy(p => p.Name))
{
    Console.WriteLine(label.Id + " - " + label.Name);
}

Console.Read();

错误:

Additional information: Google.Apis.Requests.RequestError

Bad Request [400]

Errors [

    Message[Bad Request] Location[ - ] Reason[failedPrecondition] Domain[global]

]

在IAM设置中,我使用的帐户具有完全权限:

enter image description here

该帐户具有完全权限:

enter image description here

同样,更多完整权限:

enter image description here

我错过了什么?我找不到任何有代表性的.Net请求,只需连接到框内即可。

c# google-api gmail-api google-api-dotnet-client google-identity
1个回答
0
投票

我以前从未在IAM中看到过授予域范围授权的方法。

通常,开发人员ID在域CPanel中列入白名单,如described in these docs

(该段落上写着“然后,Google Apps域管理员必须完成以下步骤”。)

© www.soinside.com 2019 - 2024. All rights reserved.