googleapis / googleapis/google-api-nodejs-client
Access a user's calendar events server side with a service account.
- Lingua principale
- TypeScript
- Stelle
- 12.2k
- Fork
- 2k
- Merge medio
- 1g 9h
- PR unite (30g)
- 24
Descrizione
I am trying to build this:
On frontend, user signs in with google and allows calendar scope permissions for full access to calendar.
On backend, some changes happen in the database of my app, I check the user's calendar events and potentially edit, insert or delete events.
---
My current implementation is like this:
```
import * as devKey from '../service-accounts/dev_key.json'
const SCOPES = [
'https://www.googleapis.com/auth/calendar',
'https://www.googleapis.com/auth/calendar.events',
]
const client = new google.auth.JWT(
devKey.client_email,
undefined,
devKey.private_key,
SCOPES,
)
await client.authorize()
const gcal = google.calendar({
version: 'v3',
auth: client
})
// Link my app to the user's calendar
const aclRes = await gcal.acl.insert({
calendarId: 'primary',
sendNotifications: true,
requestBody: {
scope: {
type: 'user',
value: 'the_user_i_want_to_access_the_calendar_of@gmail.com'
},
role: 'owner'
}
})
console.log(aclRes)
// Create a new event in the user's calendar
const event = {
summary: 'Awesome new event',
location: '800 Howard St., San Francisco, CA 94103',
description: 'This would be really cool if it worked',
start: {
'dateTime': '2023-05-28T09:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
end: {
'dateTime': '2023-05-28T17:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
recurrence: [
'RRULE:FREQ=DAILY;COUNT=2'
],
attendees: [
{ 'email': 'the_user_i_want_to_access_the_calendar_of@gmail.com' },
],
reminders: {
useDefault: false,
overrides: [
{ method: 'email', minutes: 24 * 60 },
{ method: 'popup', minutes: 10 },
],
},
}
const eventRes = await gcal.events.insert({
calendarId: 'primary',
requestBody: event
})
console.log(eventRes)
```
---
The `insert` results in this error:
```
errors: [
{
domain: 'calendar',
reason: 'forbiddenForServiceAccounts',
message: 'Service accounts cannot invite attendees without Domain-Wide Delegation of Authority.'
}
]
```
---
I've added the proper domain-wide delegation to the project that contains the service account.

---
What am I missing here?
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia dalla costruzione del client JWT e dalla chiamata a calendar.events.insert mostrati nell’issue, quindi verifica come è configurato l’account di servizio per domain-wide delegation e per quale utente agisce. Il lavoro è completato quando il server riesce a inserire un evento con un partecipante nel calendario dell’utente senza generare l’errore forbiddenForServiceAccounts.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- google-cloud, node.js, typescript
- Ambito
- api, authentication, backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100