Google Calendar API — htmlLink property of the Event does not work properly when logged in with multiple accounts - google-apis-explorer

I would like to display the link to the Calendar Event. I get the link from the Google Calendar API as part of the Event object — htmlLink property.
The problem happens when the user meets the following conditions:
They are logged in via multiple Google accounts (say, Private and Work)
The primary account does not match the one who has access to the Calendar in question
What happens next:
When the mentioned user clicks the link, they are taken to the Calendar of their primary account instead of the calendar that is associated with the event. This naturally results in permissions error.
When the user copies the URL, then goes to their calendar, then switches their account to the secondary account and insert the URL manually, then it works.
Do you guys know of a user-friendly way to mitigate this problem?

I've just found out:
In API we get htmlLink like
https://www.google.com/calendar/event?eid=[\w+]
Modify it into:
https://calendar.google.com/calendar/event?action=VIEW&eid=[\w+]
The new link leads different users to different pages:
For users logged in, location is redirected into their own calendar page, and a popup inside the webpage appears to show event information.
For clients not logged in with any Google account, there would be no redirections and a traditional page is shown.
For example: https://calendar.google.com/calendar/event?action=VIEW&eid=OGxnZ2loODc5YWU0NzM5aGc1YWtkZmxsZzhfMjAyMjEwMjlUMDUzMDAwWiB0YWl3YW5oYW5kam9iQG0
And for those who do not use Google API but want a link to an individual event:
use publish event function in the event menu to get an URL with eid, and then modify the URL manually.

Related

How to get Calendar Id from user's email using google apps script?

I am trying to create a Google calendar event for the user who submits leave request on google form. When this form response is recorded in google sheets, I get the user email id and want to create a calendar event for them. Script creates event when I use my email id, but it gives null when I try to do the same for other user.
Here is the sample code:
CalendarApp.getCalendarById(email)
.createAllDayEvent(
'OOO - Out Of Office',
startDate,
endDate,
{
description: message,
sendInvites: true,
});
I received this error: Cannot read property "createAllDayEvent" of null
I googled this error, and someone suggested that subscribing to user's calendar may solve this issue. I used the following snippet to counter that:
var calendar = CalendarApp.getCalendarById(email);
if(calendar == null){
//user may not have access, auto-subscribe them.
calendar = CalendarApp.subscribeToCalendar(email,{hidden:true,selected:false});
}
But it is showing a new error stating: The calendar or calendar event does not exist, it was deleted, or the user doesn't have access to it
Any idea how we can make it work. Thank you.
You can't do this on Form Response (at least not reliably).
To create an event in another user's calendar they must have changed their calendar settings to be available to the public and the Access Permissions must be set to 'Make changes to events'. More information about this can be read on this help page
If these settings aren't set by the user, you're out of luck creating events for them. In this case you have two options:
Create an OAuth2 Application which the user authenticates to allow the creation of Calendar events on their behalf (though this still can't be done on form submit)
Create an event on your calendar and send them an invitation using their email address. You can give them edit permissions to the event so that they have control of it as if it were in their calendar, though in this case they will have to accept the event invitation.

Communicating between Google Calendar, Google Forms and Google Spreadsheets

Consider a Google Calendar scenario with various rooms that can be booked. Users will be browsing the different rooms and can create an entry in one of the free slots. The basic default properties provided by the Google Calendar are not sufficient for the business scenario but I haven't found a way to add more fields: the default new event form does seem to be customisable. Is this so?
My idea was to provide a Google Form to cover the rest of the details.
The process would look as below:
The user browses the different rooms and finds an available slot. The calendar entry is created with the basic details. The entry is added into the calendar and the details are recorded into a Google spreadsheet.
The user receives an email with another google form: the ID of the appointment would need to somehow be passed as parameter. The google form will be used to insert the "advanced details" into the spreadsheet.
An interface will be created to view the spreadsheet data in a more structured and user friendly manner.
Can something like this be done using Google Calendars, Google Forms and App Script? Any pointers where to start from? Or if not, how the process could be changed to be actually possible. The only starting points I found were Add ins which create calendar entries directly from Google forms, but this would require the user to start from a form, rather from the calendar, which I would not rather go for, not at least until I know there's no other way.

How to send E-MAIL to organizers in Google Calendar

I need send e-mail to the organizers of a event in Google Calendar, think in that situation of a video conference meeting : A person create a event and set a location for it, but one of the guests that are in another place set a location too, and we have rules for the locations that need to be sent by email to the organizer of the event and for that guest that included the new location if that's the case. The problem is, how can I know the user that edited that location?
I have another question too, how can i get the last event that has been created on a calendar?
how i can know the user that edited that location ?
You cant unless you set up push notifications doc
How can i get the last event that has been created on a calendar?
events.list has an order by parameter that lets you sort by the start time or by the updated.

Link to private google calendar

I'm displaying events from a private Google Calendar on my CRM. I get them by authenticating using the google API. The problem is in my browser i use 2 google accounts - the first one is my personal one and the second is the one that has access to the Google Calendar I'm fetching. When I click on the link for the event it takes me to Google Calendar and says there is no such event, because by default I'm using my personal account, so i need to switch to the one that has access to the Google Calendar I'm fetching. Is there a way to tell Google that this is an event for the other user and when i click the link it takes me to the event witht the user already switched?
At the moment the link to the event looks something like this:
https://www.google.com/calendar/event?eid=NWoyODJ2NDVtMz.........

Fill Google Form from Other Google Form Responses

I have a Google form that users initially submit, say 3 weeks before an event occurs.
When the event gets closer they need to provide a final update. I would like for them to be able to select the event, probably based on the event name, and then have the form prefill in the information it already has on file (initial responses) for that event. Then the user can go in there and tweak the information and provide final details, without having to reinput all of the information all over again.
How do I do this? :-\ Thanks!
hunna03
This can be done using Google Apps Script.
So for instance, the result of the original Google Form can be stored in a Google Sheet, whose fields can be used to generate the new form.
The related documentation on creating the Google Form can be found here:
https://developers.google.com/apps-script/reference/forms/