I have .dotnet core web application. I'm trying to add event by Google Calendar Api but getting error. The error
Google.Apis.Requests.RequestError Forbidden [403] Errors [
Message[Forbidden] Location[ - ] Reason[forbidden] Domain[global] ]
My code is
Event myEvent = new Event
{
Summary = "Appointment",
Location = "Dhaka",
Start = new EventDateTime()
{
DateTime = new DateTime(2018, 9, 17, 10, 0, 0),
TimeZone = "Asia/Dhaka"
},
End = new EventDateTime()
{
DateTime = new DateTime(2018, 9, 17, 10, 30, 0),
TimeZone = "Asia/Dhaka"
},
Recurrence = new String[] {
"RRULE:FREQ=WEEKLY;BYDAY=MO"
},
Attendees = new List<EventAttendee>()
{
new EventAttendee() { Email = "alimcu08#gmail.com" }
}
};
var newEventRequest = calendarService.Events.Insert(myEvent, calendarId);
var eventResult = newEventRequest.Execute();
It's getting error when execute run. By using same calendar service I had got calendar and event list successfully but can't adding event. Any one can help?
Google provided 3 calendars whose have different id. I provided one id from them. That's why event not added. When I replace id by 'primary' it's working fine.
Related
I can create an event but I can't create an event with a conference.
I tried all these types: "eventHangout" "eventNamedHangout" "hangoutsMeet" but still getting Invalid conference type value
Google.GoogleApiException: 'Google.Apis.Requests.RequestError
Invalid conference type value. [400]
Errors [
Message[Invalid conference type value.] Location[ - ] Reason[invalid] Domain[global]
]
Here's the code that creates and executes an event:
CalendarService service = GetCalendarService();
EventDateTime start = new EventDateTime();
start.DateTime = new DateTime(2021, 02, 19, 18, 47, 0);
EventDateTime end = new EventDateTime();
end.DateTime = new DateTime(2021, 02, 19, 18, 50, 0);
Event newEvent = new Event();
newEvent.Start = start;
newEvent.End = end;
newEvent.Summary = "New event";
newEvent.Description = "description";
newEvent.ConferenceData = CreateConferenceData();
EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
request.ConferenceDataVersion = 1;
Event createdEvent = request.Execute();
Here's the code of CreateConferenceData() method:
ConferenceData conferenceData = new ConferenceData()
{
CreateRequest = new CreateConferenceRequest()
{
RequestId = Guid.NewGuid().ToString(),
ConferenceSolutionKey = new ConferenceSolutionKey()
{
Type = "hangoutsMeet" // Change according to your preferences
};
}
};
return conferenceData;
this is my service and worked perfect conference event
_calenarService = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = GenerateCredentials(),
ApplicationName = this._applicationName
});
var myEvent = new Event
{
Summary = "Google Calendar API Testing ",
Location = "Islamabad, Punjab, Pakistan",
Start = new EventDateTime()
{
DateTime = new DateTime(2021, 4, 5, 14, 0, 0),
TimeZone = "Asia/Karachi"
},
End = new EventDateTime()
{
DateTime = new DateTime(2021, 9, 10, 15, 0, 0),
TimeZone = "Asia/Karachi"
},
Recurrence = new String[] { "RRULE:FREQ=WEEKLY;BYDAY=MO" },
//If you want to add attendee
//Attendees = new List<EventAttendee>()
//{
// new EventAttendee { Email = "......com" },
// new EventAttendee { Email = "......." }
//},
ConferenceData = new ConferenceData
{
ConferenceSolution = new ConferenceSolution
{
Key = new ConferenceSolutionKey
{
Type = "hangoutsMeet"
}
},
CreateRequest = new CreateConferenceRequest
{
RequestId = "qwerfsdiob",
ConferenceSolutionKey = new ConferenceSolutionKey
{
Type = "hangoutsMeet"
},
},
EntryPoints = new List<EntryPoint> ()
{
new EntryPoint { EntryPointType = "video" },
}
}
};
var recurringEvent = _calenarService.Events.Insert(myEvent, "primary");
recurringEvent.SendNotifications = true;
recurringEvent.ConferenceDataVersion = 1;
Event eventData = recurringEvent.Execute();
Header 1
The issue was only single user adds the events in google calendar with client id and client key.
But my requirement is multiple users can add events to google calendar when click on link it redirects to google calendar login page. Events details coming from db. I attached my previous code.
string eventName = "Dummy";
DateTime startDate = new DateTime(2020, 04, 28, 16, 30, 00);
DateTime endDate = new DateTime(2020, 04, 28, 17, 00, 00);
string location = null;
startDate = DateTime.SpecifyKind(startDate, DateTimeKind.Local);
endDate = DateTime.SpecifyKind(endDate, DateTimeKind.Local);
string link = "www.sample.in";
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId ="Key",
ClientSecret = "Key",
},
new[] { CalendarService.Scope.Calendar },
"user",
CancellationToken.None).Result;
// Create the service.
var service = new CalendarService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "Calendar API Sample",
});
var myEvent = new Event
{
Summary = eventName,
Location = location,
Start = new EventDateTime
{
DateTime = startDate,
TimeZone = "Asia/India",
},
End = new EventDateTime
{
DateTime = endDate,
TimeZone = "Asia/India",
},
Recurrence = new String[] { "RRULE:FREQ=WEEKLY;BYDAY=MO" },
//Attendees = new List
//{
//new EventAttendee { Email = "xxxxx#gmail.com"}
//},
};
var recurringEvent = service.Events.Insert(myEvent, "primary");
recurringEvent.SendNotifications = true;
recurringEvent.Execute();
I was trying to create calendar using c# interop.domino.dll function call , the calendar was created successfully but the WHO field is not updated.
static void CreateMeeting(NotesDatabase userDatabase)
{
if (!userDatabase.IsOpen)
{
userDatabase.Open();
}
NotesDocument LNDocument = userDatabase.CreateDocument();
System.DateTime StartDate = new DateTime(2019, 12, 25, 6, 0, 0);
System.DateTime EndDate = new DateTime(2019, 12, 25, 6, 3, 0);
LNDocument.ReplaceItemValue("Form", "Appointment");
LNDocument.ReplaceItemValue("AppointmentType", "Meeting");
LNDocument.ReplaceItemValue("Subject", "Dec 25 - Chirstmas Celebration");
//Set Confidential Level (Public=1 or Private=0)
LNDocument.ReplaceItemValue("$PublicAccess", "1");
//Add Start&End Time of your event
LNDocument.ReplaceItemValue("CALENDARDATETIME", StartDate);
LNDocument.ReplaceItemValue("StartDateTime", StartDate);
LNDocument.ReplaceItemValue("EndDateTime", EndDate);
LNDocument.ReplaceItemValue("StartDate", StartDate);
LNDocument.ReplaceItemValue("Location", "Meeting Hall");
//Add From and To
LNDocument.ReplaceItemValue("Chair", "test/test#test");
LNDocument.ReplaceItemValue("From", "test#DS.test.com");
LNDocument.ReplaceItemValue("Required", "test1/test1");
LNDocument.ReplaceItemValue("EnterSendTo", "test1#DS.test.com");
LNDocument.ReplaceItemValue("SendTo", "test1#DS.test.com");
//Infos in The Body
LNDocument.ReplaceItemValue("Body", "Chirtsmas DAY ...");
LNDocument.ComputeWithForm(true, false);
LNDocument.Save(true, false, false);
}
What is the mistake i am doing with the creation here ?
I need help to create a new event inside Google calendar. I followed this link
and its working fine but now I need to add new event and delete event(existing/new) and I couldn't able to figure out how to add events. I tried this example to insert new events in calendar:link
but when i compile it gives me an error and here is the screen shot.
I will really appreciate help.
To add new event and send invite:
Event myEvent = new Event
{
Summary = "Discussion on new project",
Location = "Mentor",
Start = new EventDateTime()
{
DateTime = new DateTime(2018, 8, 16, 10, 0, 0),
TimeZone = "America/Los_Angeles"
},
End = new EventDateTime()
{
DateTime = new DateTime(2018, 8, 16, 11, 30, 0),
TimeZone = "America/Los_Angeles"
},
Recurrence = new String[] { "RRULE:FREQ=WEEKLY;BYDAY=MO"},
Attendees = new List<EventAttendee>()
{
new EventAttendee() { Email = "abc#gmail.com" }
}
};
var recurringEvent = service.Events.Insert(myEvent, "primary");
recurringEvent.SendNotifications = true;
recurringEvent.Execute();
I need to mock a method from the google calendar api. But it gives an error everytime. I have the following code.
DateTime dateTimeNow = new DateTime(2018, 10, 10, 10, 10, 10);
Event events = new Event
{
Id = "EventA",
Summary = "Summary",
Description = "Desc",
Start = new EventDateTime { Date = "2018-10-10", DateTime = dateTimeNow},
End = new EventDateTime { Date = "2018-10-10", DateTime = dateTimeNow.AddHours(1) },
};
Mock<CalendarService> fakeCalendarService = new Mock<CalendarService>();
fakeCalendarService
.Setup(x => x.Events.Insert(It.IsAny<Event>(), It.IsAny<string>()).Execute())
.Returns(events);
I get the following error message:
Message: System.NotSupportedException : Invalid setup on a non-virtual (overridable in VB) member: x => x.Events.Insert(It.IsAny<Event>(), It.IsAny<String>()).Execute()
I was able to mock other functions but this function:
_service.Events.Insert(newEvent, _calendarId).Execute();
has .Execute() behind it. Because of this statement I don't know how to mock it.