我可以通过API从Google幻灯片获取演讲者备注吗? [英] Can I get speaker notes from Google Slides by API?
问题描述
我想通过API从Google幻灯片获取演讲者注释,但是找不到演讲者注释的任何字段.
I want to get speaker notes from Google Slides by API, but I could not find any fields for speaker notes.
供参考:方法: presentations.pages.get
什么是做到这一点的好方法?
What would be a good way to do this?
推荐答案
在没有API的情况下,我不建议这是一种好的方法.实际上,这是可怕的.但是在这里.如果您绝对必须这样做.它也可能有点苦涩.
In the absence of the API, I wouldn't suggest this is a good way of doing it. In fact it is horrible. But here it is. If you absolutely had to do it. It is likely a bit flakey too.
步骤是:
- 通过Drive API将演示文稿导出为PowerPoint .pptx文件
- 解压缩文件-这是一个zip文件,其中包含带有XML文件的目录结构.
- 识别演讲者注释文件并根据您的要求进行处理(例如,提取所有文本,或处理XML等).
丑陋吧?这是Apps脚本中的示例:
Ugly right? Here's an example in Apps Script:
-
在脚本(资源>高级Google服务)中的Advanced Services中启用 Drive API .
Enable Drive API in Advanced Services within your script (Resources > Advanced Google Services).
function example() {
// Print out the speaker notes
Logger.log(getNotes('123abc......asd'));
}
// Returns an array of strings, one string per slide
// representing the speaker notes.
function getNotes(presentationId) {
//DriveApp.createFile();
var notesRegex = /ppt\/notesSlides\/notesSlide\d+\.xml/;
var url = 'https://www.googleapis.com/drive/v2/files/' + presentationId +
'/export?mimeType=application%2Fvnd.openxmlformats-officedocument.presentationml.presentation';
var options = {
headers: {
Authorization : 'Bearer ' + ScriptApp.getOAuthToken()
}
};
var response = UrlFetchApp.fetch(url, options);
var zipBlob = Utilities.newBlob(response.getContent(), 'application/zip');
var data = Utilities.unzip(zipBlob);
var notes = [];
for (var i = 0; i < data.length; i++) {
if (notesRegex.test(data[i].getName())) {
// Example simply extracts text from speaker notes
// You could do something more complex.
notes.push(extractTextFromXml(data[i].getDataAsString()));
}
}
return notes;
}
function extractTextFromXml(xml) {
var doc = XmlService.parse(xml);
var root = doc.getRootElement();
var ns = root.getNamespace('a');
var text = [];
function walkNode(node) {
if (node.getText()) {
text.push(node.getText());
}
var children = node.getChildren();
if (children.length) {
children.forEach(function(child) {
walkNode(child);
});
}
}
walkNode(root);
return text.join('\n');
}
这篇关于我可以通过API从Google幻灯片获取演讲者备注吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!