Google app maker 从Google Drive启动Appmaker文档审批

Google app maker 从Google Drive启动Appmaker文档审批,google-app-maker,Google App Maker,我已经根据需要在Appmaker中定制了文档管理系统模板。现在,我想提供从Google Drive启动工作流的功能,而不是每次都去Appmaker启动审批。因此用户可以直接从Google Drive选择要审批的文件 我的问题是,是否有任何Rest呼叫或其他东西可以让我从第三方应用程序启动DMS工作流?好吧,我找到了一个实现结果的方法 步骤: 驱动API提供了一种在Google Drive的“打开方式”菜单中添加应用程序的方法 因此,我创建了我的自定义应用程序并进行了部署。此应用程序只需从Goog

我已经根据需要在Appmaker中定制了文档管理系统模板。现在,我想提供从Google Drive启动工作流的功能,而不是每次都去Appmaker启动审批。因此用户可以直接从Google Drive选择要审批的文件


我的问题是,是否有任何Rest呼叫或其他东西可以让我从第三方应用程序启动DMS工作流?

好吧,我找到了一个实现结果的方法

步骤:

  • 驱动API提供了一种在Google Drive的“打开方式”菜单中添加应用程序的方法
  • 因此,我创建了我的自定义应用程序并进行了部署。此应用程序只需从Google Drive的“打开方式”菜单接收参数,并将其传递给Appmaker文档审批系统
  • 在Appmaker创建请求页面中,分析请求是否包含这些参数,如果是,则选择使用这些参数的文件
  • 这样,我的用户就可以从Google Drive启动文档审批工作流
  • 参考文献:

  • 代码:

  • “打开方式”应用程序代码,用于将用户从Google Drive重定向到Appmaker
  • 代码G.gs:

    var AUTHORIZE_URL = 'https://accounts.google.com/o/oauth2/auth'; 
    var TOKEN_URL = 'https://accounts.google.com/o/oauth2/token'; 
    
    var REDIRECT_URL= ScriptApp.getService().getUrl();
    var tokenPropertyName = 'GOOGLE_OAUTH_TOKEN'; 
    
    var CLIENT_ID = 'your client id';
    var CLIENT_SECRET = 'your client secrect';
    
    function doGet(e) {
      var HTMLToOutput;
    
      if(e.parameters.state){
        var state = JSON.parse(e.parameters.state);
        if(state.action === 'create'){
          HTMLToOutput = "<html><h1>Creation Of Docs Not supported by this App!</h1></html>"; 
        }
        else {
          var id = state.exportIds;
           var file = DriveApp.getFileById(id);
           //append params to your appmaker URL
          var url = 'yourappmaker published url'+'?param1='+file.getName()+'&param2='+file.getUrl()+'#AddRequest';
          HTMLToOutput = HtmlService.createHtmlOutput('<html><script>'
      +'window.close = function(){window.setTimeout(function(){google.script.host.close()},9)};'
      +'var a = document.createElement("a"); a.href="'+url+'"; a.target="_blank";'
      +'if(document.createEvent){'
      +'  var event=document.createEvent("MouseEvents");'
      +'  if(navigator.userAgent.toLowerCase().indexOf("firefox")>-1){window.document.body.append(a)}'                          
      +'  event.initEvent("click",true,true); a.dispatchEvent(event);'
      +'}else{ a.click() }'
      +'close();'
      +'</script>'
      // Offer URL as clickable link in case above code fails.
      +'<body style="word-break:break-word;font-family:sans-serif;">Failed to open automatically. <a href="'+url+'" target="_blank" onclick="window.close()">Click here to proceed</a>.</body>'
      +'<script>google.script.host.setHeight(40);google.script.host.setWidth(410)</script>'
      +'</html>')
      .setWidth( 90 ).setHeight( 1 );
        }
      }
      else if(e.parameters.code){//if we get "code" as a parameter in, then this is a callback. we can make this more explicit
        getAndStoreAccessToken(e.parameters.code);
        HTMLToOutput = '<html><h1>App is installed, you can close this window now or navigate to your <a href="https://drive.google.com">Google Drive</a>.</h1></html>';
      }
      else {//we are starting from scratch or resetting
        HTMLToOutput = "<html><h1>Install this App into your Google Drive!</h1><a href='"+getURLForAuthorization()+"'>click here to start</a></html>";
      }
      console.log(getURLForAuthorization());
      return HtmlService.createHtmlOutput(HTMLToOutput);
    }
    
    function getURLForAuthorization(){
      return AUTHORIZE_URL + '?response_type=code&client_id='+CLIENT_ID+'&redirect_uri='+REDIRECT_URL +
        '&scope=https://www.googleapis.com/auth/drive.install https://www.googleapis.com/auth/userinfo.email';  
    }
    
    function getAndStoreAccessToken(code){
      var parameters = { method : 'post',
                        payload : 'client_id='+CLIENT_ID+'&client_secret='+CLIENT_SECRET+'&grant_type=authorization_code&redirect_uri='+REDIRECT_URL+'&code=' + code};
    
      var response = UrlFetchApp.fetch(TOKEN_URL,parameters).getContentText();   
      var tokenResponse = JSON.parse(response);
      UserProperties.setProperty(tokenPropertyName, tokenResponse.access_token);
    }
    
    function getUrlFetchOptions() {
      return {'contentType' : 'application/json',
              'headers' : {'Authorization' : 'Bearer ' + UserProperties.getProperty(tokenPropertyName),
                           'Accept' : 'application/json'}};
    }
    
    //naive check, not using for now, use refresh tokens and add proper checking
    function isTokenValid() {
      return UserProperties.getProperty(tokenPropertyName);
    }
    
    这一个应该是相关的,而这一个在某种程度上是相关的。剧透警报:要做到这一点并不容易。
    function checkIfRedirected(widget)
    {
    //   console.log(location.origin);  
      google.script.url.getLocation(function(location) {
      var params = location.parameter;
      var param1 = params.param1;
        var param2 = params.param2;
        widget.datasource.item.DocumentName = param1;
        widget.datasource.item.DocumentUrl = param2;    
        widget.datasource.item.Owner = app.user.email;
      });
    }