beibei2
beibei2

Reputation: 815

Calling method on pageElement fails with error "TypeError: Cannot find function"

I'm trying to write a script that looks at each pageElement on each slide of a presentation and outputs the source URL of any IMAGE elements. However, I'm stuck at the most elementary stage: any time I call a documented method of pageElement, I get an error like:

TypeError: Cannot find function getPageElementType in object {"transform":

It seems as if slide.pageElements[i] is returning a plain data object, like a JSON file devoid of any function prototypes. I can't call any of the standard object methods, even things like getHeight(), etc.

This is a code stub I can't get to run without error:

function test() {
  var presentationId = INSERT_ID_HERE;
  var presentation = Slides.Presentations.get(presentationId);
  var slides = presentation.slides;
  slides[0].pageElements[0].getPageElementType();
}

I'm testing this against a presentation with a single slides with two elements on it (one of which is an image). What am I doing wrong?

Upvotes: 1

Views: 447

Answers (1)

tehhowch
tehhowch

Reputation: 9862

You're using Apps Script Slides Service SlidesApp methods on the result of the Slides API (the "advanced service" client library Slides). The Slides API indeed returns JSON representations, while the Slides Service returns objects of defined type, with class methods.

You can review the JSON resource representations on the API site:https://developers.google.com/slides/reference/rest/

Upvotes: 1

Related Questions