Google Apps Script Custom Menu / createMenu not displaying in Slide when presentation opens

旧城冷巷雨未停 提交于 2021-02-11 14:41:48

问题


Does createMenu work differently for slides than it does for spreadsheets?

Is this a bug or is something wrong with my code? Should it be reported?

SIMPLE TEST - - - - - - - DOES NOT CREATE MENU ON OPEN FROM DRIVE OR REFRESH

function onOpen() {
  console.log('In onOpen' );
  
  const pres = SlidesApp.getActivePresentation();
  const slideSet = pres.getSlides();
  
  let ui;
  try {
    ui = SlidesApp.getUi();
    console.log('getUi succeeded' );
  }  catch (e)  {
    console.log('caught in getUi: ', e );
  }
  
  try {
    ui.createMenu( 'Ask ?')
      .addItem('BE1', 'BE1') 
      .addToUi(); 
  }  catch (e)  {
    console.log('caught in createMenu: ', e );
  }
  
console.log('    after create menu');
  // let result = ui.alert('sample title', 'Please click "ask?" to begin.', ui.ButtonSet.OK);  
}

For this one there is no AUTH problem as there is almost no code.

Manifest

{
  "timeZone": "America/Mexico_City",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8"
}

If you are curious the function called from the menu - BE1

/**
 * Create a new square textbox, using the supplied element ID.
 */
function BE1 () {
  let pres = SlidesApp.getActivePresentation();
  let slideSet = pres.getSlides();
  let shape = slideSet[0].insertShape(SlidesApp.ShapeType.TEXT_BOX, 200, 300, 60, 60);
  let textRange = shape.getText();
  textRange.setText('Hello world!');
}

It really looks like create menu does not work upon slide presentation open or refresh despite Google documentation. Is this a bug? Can someone who knows how please report it?

= = = = = = = = = = = = = = = = = = =

Presentation That does open window.

function onOpen() {

  let ui = SlidesApp.getUi();

  let pres;
  let slideSet = [];
  try {
    pres = SlidesApp.getActivePresentation();
    slideSet = pres.getSlides();
  }    catch (err) {
    console.log('get active presentation err: ', err);
  }
  
    SlidesApp.getUi()
      .createMenu( 'Ask ?')
      .addItem('BE1','BE1')
      .addToUi(); 

}

Manifests:

{
  "timeZone": "America/Mexico_City",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8"
}

Error when loaded from drive: get active presentation err: { [Exception: Authorization is required to perform that action.] name: 'Exception' }

If you stop the program because of the error, the menu is not created. If you run from the script editor you do not get the authorization error.

来源:https://stackoverflow.com/questions/65615455/google-apps-script-custom-menu-createmenu-not-displaying-in-slide-when-present

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!