首页 > 解决方案 > 有没有一种方法可以让我从谷歌幻灯片中应用程序脚本的 onOpen 函数中运行 SlidesApp.openById() ?

问题描述

function onOpen() {
    // Add a custom menu to the google slide.
    let menu = SlidesApp.getUi().createMenu('EditAddon')
    menu.addItem('Edit Text', 'editText')
    menu.addToUi();
}

这是我的 onOpen 函数,它工作正常。但是当我把它改成下面的代码时,

function onOpen() {
    // Add a custom menu to the google slide.
    let menu = SlidesApp.getUi().createMenu('EditAddon')
    menu.addItem('Edit Text', 'editText')
    menu.addToUi();
    const slides = SlidesApp.openById("myslideidgoeshere").getSlides();
}

我收到一条错误消息,说“例外​​:您无权调用 SlidesApp.openById。所需权限:https ://www.googleapis.com/auth/presentations at onOpen

我浏览了一些参考资料,发现我需要在清单文件中添加权限。而且,也这样做了。下面的代码来自我的清单文件(appsscript.json)。

{
  "oauthScopes": [
                  "https://www.googleapis.com/auth/presentations.readonly",
                  "https://www.googleapis.com/auth/userinfo.email",
                  "https://www.googleapis.com/auth/presentations"
                 ],
   "timeZone": "Asia/Kolkata",
   "dependencies": {},
   "exceptionLogging": "STACKDRIVER",
   "runtimeVersion": "V8"
}

但我仍然面临同样的问题。我需要的是,当用户安装我的插件时,他应该被重定向到 googleslides,其中打开了所谓的演示文稿。有没有人可以帮助我解决这个问题?

标签: google-apps-scriptgoogle-slides

解决方案


推荐阅读