问题
I need to add a Google Drawing to a Google Doc and I would like to know if that is possible using the API.
I have been able to modify the Drawing using the Slides API (see code below) but I am not able to link this Slide to the Google Doc.
function logSlidesAndElements() {
var presentationId = 'id_id_id_id_id_...';
var presentation = Slides.Presentations.get(presentationId);
var slides = presentation.slides;
// Log the elements in the slide
for (var i = 0; i < slides[0].pageElements.length; i++) {
if (slides[1].pageElements[i]['shape']['shapeType'] == 'TEXT_BOX') {
Logger.log(i);
Logger.log(slides[1].pageElements[i]['objectId']);
Logger.log(slides[1].pageElements[i]['shape']['text']['textElements'][1]['textRun']['content']);
}
}
// Modify one of the elements
var requests = [{
updateShapeProperties: {
objectId: slides[1].pageElements[8]['objectId'],
fields: 'shapeBackgroundFill.solidFill.color',
shapeProperties: {
shapeBackgroundFill: {
solidFill: {
color: green_application_map
}
}
}
}
}];
var batchUpdateResponse = Slides.Presentations.batchUpdate({
requests: requests
}, presentationId);
}
I see there is a list of inlineObjects inside the document body[1], and if I add a linked slide manually (copy and paste from google slides to google doc) to the google Doc and print the document object with code below
var document = Docs.Documents.get(doc_id);
var docElements = document;
console.log(docElements);
What I see is (just the relevant part):
kix.l46ge8x1m={
...
inlineObjectProperties={
linkedContentReference={
},
imageProperties={
cropProperties={
},
contentUri=https://lh6.googleusercontent.com/really_long_id_to_the_generated_image_from_the_slide
}
...
},
objectId=kix.l46ge8x1m
}
There is a link to an image generated from the drawing but I don't see anything related to the linked Slide.
I would expect to see something inside the linkedContentReference but is empty so I am not sure if is possible to link the generated Slide (and Drawing) to the Doc.
[1] https://developers.google.com/docs/api/reference/rest/v1/documents
来源:https://stackoverflow.com/questions/58312843/linking-a-google-slide-and-drawing-to-a-google-doc-using-api