I have created ASP.NET MVC web application to integrate with google calendar API.
I have followed the documentation in Google sites. I have set up the project in Google Developer console as follows:
I have also downloaded the credentials files after creating the project but while using it i am getting uri_mismatch
error every time.
How can this be solved?
My code for authorization is :
string jsonFile = HttpContext.Server.MapPath("~/credentials.json");
UserCredential credential;
using (var stream =
new FileStream(jsonFile, FileMode.Open, FileAccess.Read))
{
// The file token.json stores the user's access and refresh tokens, and is created
// automatically when the authorization flow completes for the first time.
//string credPath = "token.json";
string credPath = HttpContext.Server.MapPath("~/token");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
// Create Google Calendar API service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define parameters of request.
EventsResource.ListRequest request = service.Events.List("primary");
request.TimeMin = DateTime.Now;
request.ShowDeleted = false;
request.SingleEvents = true;
request.MaxResults = 10;
request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;