I am trying to use the google APIs to read emails and I'm repeatedly failing to get good results. It is supposed to be a server->server account that runs periodically in the background, but I can't get it to connect. The code is basic:
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();
Error:
Additional information: Google.Apis.Requests.RequestError
Bad Request [400]
Errors [
Message[Bad Request] Location[ - ] Reason[failedPrecondition] Domain[global]
]
In IAM settings, the account I'm using has full permissions:
The account has full permissions:
Likewise, more full permissions:
What am I missing? I can't find any representative .Net requests that make sense in just connecting to an in box.