Google-sheets – Updating slides from sheet

google sheetsgoogle-apps-scriptgoogle-slides

I am trying to update slides from sheet. As simple as that.

  1. I have a working script in sheet which updates the slide if I run it from the gscript editor
  2. I want this script to run onEdit of specific cell in spreadsheet
  3. So I add function

    function onEdit(e) {
      if ([e.range is what I want]){
        [update the slide using Slides.Presentations.batchUpdate]
    }
    
  4. Upon changing the cell, I can see in my G Suite developer HUB an error message Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

I am very new in this environment and I only wanted to achieve something simple. What am I missing? Do I really need to register new OAuth2 client app in google cloud platform to connect one google product to another?

Best Answer

I figured the answer finally:

  1. onEdit, as a simple trigger can't access advanced services (like slides)
  2. Turns out I don't need advanced services at all, I only need a drawing on a sheet to trigger script and UrlFetchApp call with proper OAuth authentication, like that:
    var options = {
      'method' : 'post',
      'contentType': 'application/json',
      'payload' : JSON.stringify(requests),
      'headers': {
        'Authorization': 'Bearer ' + ScriptApp.getOAuthToken()
      }
    };