I am building an organisation level flutter application in which user can enroll for the particular google calendar event. This calendar events are created by admin account of organisation. So, to access/modify events I have created an AppsScript on that admin account and deployed that as a Web app and has access as Anyone within <organisation>
. But I am getting Unauthorized error from the server.
Here is my AppsScript code:
function doGet(request) {
const calendarId = \<calendar_id\>;
const calendar = CalendarApp.getCalendarById(calendarId);
const requestEventId = request.parameter.eventId;
const event = calendar.getEventById(requestEventId);
const guestMail = request.parameter.email;
event.addGuest(guestMail);
return ContentService.createTextOutput(JSON.stringify("result")).setMimeType(ContentService.MimeType.JSON);
}
Now from my flutter application I am passing EventId and logged in user MailId to this function to add this user to event guest list. Here is the code snippet for the same:
void addGuestToUpcomingEvent(EventRequestData eventRequestData, String? accessToken) async {
final response = await http.get(
Uri.parse(\_appScriptUrl + eventRequestData.toParams()),
headers: {
'Authorization': 'Bearer $accessToken',
});
print(response.body)
}
Even when I am passing the header with proper accessToken I am getting 401 from the server with error message as: Unauthorized
Let me know if I need to do any configurations to access apps script in my flutter application.