google-slides
NPM package for some simple Google Slides operations
contents
prerequisites
preparation
- visit the Google developers console
- create a new project
- enable the Google Drive and Google Slides APIs for your project
- create a service account connected to your project
- generate and download JSON credentials for your service account
installation
npm install google-slides
Presentation
copy
const api = 'path/to/credentials.json'const presentationId = '1yMEqtOta984dwNyJoeU92tsC5x7GV2fQK7V4wJc60Mg'const template = id: presentationId apitemplate
share
See API.sharePresentation.
Instead of api.sharePresentation
use presentation.share
and don't pass id
.
batchUpdate
See API.presentationBatchUpdate.
Instead of api
use presentation
and don't pass presentationId
.
API
const api = 'path/to/credentials.json'
copyPresentation
api
sharePresentation
const emailAddress = 'wpbdry@gmail.com'const role = 'writer' // One of: owner | organizer | fileOrganizer | writer | commenter | readerconst type = 'user' // One of: user | group | domain | anyoneconst sendNotificationEmails = false api
presentationBatchUpdate
const api = 'path/to/credentials.json' api
TextReplacement
Replaces all instances of text matching a criterion with replaceText
. \
const text = '{{some-text-to-replace}}'const replaceText = 'Replacement Text'const matchCase = true // defaultconst textReplacement = text replaceText matchCase
ShapeReplacementWithImage
Replaces all shapes that match the given criteria with the provided image.
const text = '{{text-contained-within-shape}}'const imageUrl = 'https://example.com/my-img'const matchCase = true // defaultconst replaceMethod = 'CENTER_INSIDE' // defaultconst shapeReplacement = text imageUrl matchCase replaceMethod
underlying services
The API class implements underlying services, which can be accessed directly if they are await
ed.
This provides access to further functions from the googleapis
module, which may not be implemented here.
driveService
{ const api = 'path/to/credentials.json' await apidriveService}
The driveService
object here is equivelant to the drive
object used in all the Node.js snippets in the
Google Drive API V3 documentation
slidesService
{ const api = 'path/to/credentials.json' await apislidesService}
The slidesService
object here is equivelant to the slides
or this.slidesService
objects used in all the Node.js snippets in the
Google Slides API documentation
await
?
why When new API('path/to/credentials.json')
is called, the API logs in with the provided credentials, and initialized the underlying services.
Since logging in happens asynchronously, the services may not yet exist by the time they are used. These services are await
ed every time
they are used in the built in methods. You only need to await
each service the first time you use it in any single promise chain.