You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

迁移至V8运行时后Slides App调用getActivePresentation报错

Fix "Exception: Action not allowed" in V8 Runtime for Cross-Account Slides Scripts

Let's break down why this is happening and how to fix it—this is a common gotcha when switching to V8 from the old ES5 runtime, especially with non-container-bound scripts and cross-account scenarios.

Why This Error Occurs

The V8 runtime enforces stricter permission boundaries than the deprecated ES5 mode. Here's the core issue:

  • Non-container-bound scripts run under the authorization context of the Google account they're tied to, not the account that has the Slides presentation open.
  • When you use SlidesApp.getActivePresentation() (or even openById() with a presentation owned by a different account), V8 blocks the action because the script's account doesn't have explicit permission to access that presentation—even if you can see it in your browser.
  • In ES5, this permission check was more lenient, which is why it worked before.

Solution 1: Migrate to a Container-Bound Script (Simplest Fix)

This is the most reliable approach since container-bound scripts inherit the permission context of the presentation they're attached to:

  1. Open the Google Slides presentation you're working with.
  2. Go to Extensions > Apps Script to create a new container-bound script tied directly to this presentation.
  3. Copy your existing imageToSlide function into this new script.
  4. Update your HTML template's google.script.run call to point to this bound script's function. Now SlidesApp.getActivePresentation() will work seamlessly, even across accounts, as long as the user has edit access to the presentation.

Solution 2: Fix Permissions for Non-Container-Bound Scripts

If you can't switch to a container-bound script, you'll need to explicitly grant permissions and adjust your code:

Step 1: Configure Correct OAuth Scopes

  • In your Apps Script editor, go to Project Settings > Show "appsscript.json" manifest file.
  • Open appsscript.json and make sure your oauthScopes include the necessary permissions for Slides access:
    "oauthScopes": [
      "https://www.googleapis.com/auth/presentations",
      "https://www.googleapis.com/auth/script.container.ui"
    ]
    

Step 2: Grant the Script's Account Access to the Presentation

  • Share the target Slides presentation with the Google account that owns your non-container-bound script, and give it Edit permissions. This ensures the script's account can access the presentation programmatically.

Step 3: Pass the Presentation ID Explicitly

  • From your HTML template, extract the presentation ID from the Slides URL (it's the string between /d/ and /edit).
  • Modify your google.script.run call to pass this ID as a parameter:
    // HTML side: Extract ID from the current Slides URL
    const presentationId = window.location.href.split('/d/')[1].split('/')[0];
    google.script.run
      .withSuccessHandler(sidebar.onSuccess)
      .withFailureHandler(sidebar.onAddDocumentError)
      .imageToSlide(presentationId, url, link, width, height);
    
  • Update your imageToSlide function to use openById() with the passed ID:
    function imageToSlide(presentationId, url, link, width, height) {
      try {
        const presentation = SlidesApp.openById(presentationId);
        // Your existing logic to add the image goes here
        return "Image added successfully";
      } catch (err) {
        console.error("Error accessing presentation:", err);
        throw err;
      }
    }
    

内容的提问来源于stack exchange,提问作者Yanko Shterev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 18:42:43