I'm trying to create a Google Calendar Service Account.
Here are my credentials:
Here's my service account definition (Site Wide delegation for service account is enabled):
Here's my "Manage API client access" page:
And this is my code:
string userName = "[email protected]";
string[] Scopes = { CalendarService.Scope.Calendar, CalendarService.Scope.CalendarEvents };
string ApplicationName = "Client per quickstart";
ServiceAccountCredential credential = GoogleCredential.FromFile(@"path\credentialjson.json").CreateScoped(Scopes).CreateWithUser(userName).UnderlyingCredential as ServiceAccountCredential;
// Create Google Calendar API service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName
});
// THIS REQUEST FAILS!!
var y = service.CalendarList.List().Execute();
The service is created correctly but all requests fail with this error:
Code: 401, Message: "Invalid Credentials", Location: "Authorization", >LocationType: "header", Reason: "authError", Domain: "global"
I don't understand what I'm missing in the authorization header.
What should I set before the request that was not done when creating the service? Thanks!