首页 > 解决方案 > Google 应用程序脚本无法由所有者运行脚本

问题描述

我的所有者拥有文档、工作表、幻灯片、表单的附加组件。
我有编辑器
,我尝试以所有者身份运行测试脚本google.script.run,脚本返回“loadImg 错误(代码:47)”。
如果我尝试将测试脚本作为编辑器运行,则脚本运行良好。
什么是错误代码:47?为什么错误只针对所有者?

客户端代码

window.google.script.run
  .withSuccessHandler(() => { resolve({ success: true }) })
  .withFailureHandler((err) => {
    console.log('error', err);
    reject({ reject: true })
  })
  .loadImg({ data: someData })

应用脚本代码

function loadImg (params) {
  let docType = null
  if (DocumentApp.getActiveDocument())       docType = 'docs'
  if (SpreadsheetApp.getActiveSpreadsheet()) docType = 'sheets' 
  if (SlidesApp.getActivePresentation())     docType = 'slides' 
  if (FormApp.getActiveForm())               docType = 'form' 

  // Create Blob
  const imgByte = Utilities.base64Decode(params.img)
  const blob = Utilities.newBlob(imgByte, MimeType.PNG, params.name)

  // Append a new Image.
  if (docType === 'docs')   addIconInDoc(blob)
  if (docType === 'sheets') addIconInSheets(blob)
  if (docType === 'slides') addIconInSlides(blob)
  if (docType === 'form')   addIconInForm(blob, params.name)
}

标签: google-apps-script

解决方案


推荐阅读