The application I'm developing is a google calender api, which does google calendar integration.
I would like to get the email address associated with the linked calendar, but I can't figure out how to do that by looking at the following url.
https://developers.google.com/calendar/api/v3/reference/calendars
Calendars dont have email addresses. They have calendar id's this for example would be a calendar id
v205qep4g260mm7fgq8vtgp18@group.calendar.google.com
It may look like an email address but it is not. You cant send it an email there for it is not an email address.
If you do a calendar.get on the primary calendar
curl \ 'https://www.googleapis.com/calendar/v3/calendars/pramary?key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
The calendar id of that calendar is actually the email address of the currently authenticated user
{
"kind": "calendar#calendar",
"etag": "\"j32ipQvsbvz0_YlxYi3Ml2Fd7A\"",
"id": "xxxxx@gmail.com",
"summary": "Linda Lawton ",
"description": "test",
"timeZone": "Europe/Copenhagen",
"conferenceProperties": {
"allowedConferenceSolutionTypes": [
"hangoutsMeet"
]
}
}
This will however not work with other calendars the one above is my house hold cleaning calendar.
If what you are actually trying to do id get the email address of the owner of the calendar then you should be using acl.list this method will return to you all the rules for the calendar
curl \
'https://www.googleapis.com/calendar/v3/calendars/p4g260mm7fgq8vtgp18%40group.calendar.google.com/acl?key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
One of those rules is the owners email
{
"kind": "calendar#aclRule",
"etag": "\"00001501683456631000\"",
"id": "user:XXXXX@gmail.com",
"scope": {
"type": "user",
"value": "XXXXX@gmail.com"
},
"role": "owner"
},
I altered the node quickstart a little to show how to use this method
/**
* Lists the next 10 events on the user's primary calendar.
* @param {google.auth.OAuth2} auth An authorized OAuth2 client.
*/
function listEvents(auth) {
const calendar = google.calendar({version: 'v3', auth});
calendar.acl.list({
calendarId: 'primary',
}, (err, res) => {
if (err) return console.log('The API returned an error: ' + err);
const rules = res.data.items;
if (rules .length) {
rules .map((rule, i) => {
console.log(`User ${rule.id} with the role ${rule.role}`)
});
} else {
console.log('No upcoming rules found.');
}
});
}