So, I spent a ridiculous amount of time googling about this issue. Basically, this is my auth code:
UserCredential credential;
using (var stream =
new FileStream(@"C:\Users\Marto\Desktop\project\MVC_2b\App_Data\client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
// Create Google Calendar API service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
ApiKey = "key",
});
And this is where the error occurs: (error 401 on Execute())
Calendar calendar=new Calendar();
calendar.Id = "Test";
service.Calendars.Insert(calendar).Execute();
This is my error:
An exception of type 'Google.GoogleApiException' occurred in Google.Apis.dll but was not handled in user code
Additional information:
Google.Apis.Requests.RequestError - Invalid Credentials [401]
Errors [Message[Invalid Credentials] Location[Authorization - header] Reason[authError] Domain[global]]
I am not sure if I am not doing something right with the authorization tho.
Any help would be appreciated, Thank you!