I have a Google App for Business.
Is it possible to access other user's calendar to input & retrieve event?
I only know how to do it for my own calendar, but not others.
I have super administrator access.
Yes, you can get any calendar by it's ID, and then just get the events. As per your comment I don't believe that it will allow you to get any calendar in the domain, you appear to need to be subscribed. Whether this is expected or not I'm unsure.
Enter the Advanced Calendar Service, which uses the Calendar API to manage your domains calendars (and I suspect is probably the correct way to go about managing your domains calendars). After you turn the calendar service on, you can do what your looking for simply like so:
function calendar(){
var cal = Calendar.Calendars.get('calendar#domain');
Logger.log(cal.summary);
};
Which will return the 'name' of the calendar. (Note: For primary calendars, the 'name' of the calendar is almost always the same as the calendar ID).
Related
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.
Been using CalendarApp to help aggregate multiple Google calendars from different accounts into a single formatted spreadsheet which has been working beautifully. However, we want to incorporate more than just these calendars into the system and have been having trouble retrieving data from an imported calendar that we are subscribed to.
This calendar is from Trello (uses a power-up to create a calendar based on due dates) which provides a URL for us to subscribe to on Google. When I attempt to use the same CalendarApp.getCalendarById(calendarId), it doesn't appear to be able to access the event data and returns null.
For reference, here is the calendar id: mp9si8iqi6uop4a20pr0r1v000dc9pcu#import.calendar.google.com. The format is slightly different from Google calendars ending in #group.calendar.google.com.
Are we able to access calendar information from imported calendars like these? I tried .getCalendarsByName(calendarName) as well with no luck, but is there another way to view this data and include it in our calendar spreadsheet? Any help is appreciated!
Edit (by request)
If I was unclear, I tried the following:
calendarId = "mp9si8iqi6uop4a20pr0r1v000dc9pcu#import.calendar.google.com";
CalendarApp.getCalendarById(calendarId);
//and
calendarName = "Collab, Events & Special Buy";
CalendarApp.getCalendarsByName(calendarName);
Only an issue with this calendar which is managed by Trello
You can definitely get information from imported calendars. Please try using the following code:
function myFunction() {
var calendarId = "YOUR_CALENDAR_ID";
var cal = CalendarApp.getCalendarById(calendarId);
Logger.log(cal.getName());
Logger.log(cal.getDescription());
Logger.log(cal.getTimeZone());
Logger.log(cal.getColor());
}
Run it, and navigate to View>Logs. You should be able to see the calendar's information. I recommend you also try the following:
Use the "Try this API" feature
List all your calendars and find the one you desire. You should be able to find it, and also extract its id. https://developers.google.com/calendar/v3/reference/calendarList/list
List the events on your calendar. You only have to set the calendarId value that you have just retrieved and execute it. You should be able to see the events on your calendar. https://developers.google.com/calendar/v3/reference/events/list
I have a Google Sheets Add-on about which I'd like to determine feasibility of monetizing. To do this I'd like to see frequency level of users; users per domain as well as how often they use the add-on.
I've read a bit about properties in the documentation, and I'm pretty sure that is at the heart of what I need to work on to start getting this data. My question is about routing that to a form I can use to crunch numbers.
I have considered just having the Properties Service send the user's email and date generated in the Add-on (not the current date, but the date for the content generated). Once that gets sent to a spreadsheet in my drive, I can use a script bound to the spreadsheet to determine if the user has been logged yet. If so, we move the date to the row for that user. If not, we create a new entry. I can also have the script order users based on domain so I can see domains with heavier usage.
I've never done this before, so I'm looking to see if I'm thinking in the right direction or if I'm overlooking something.
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.
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.