从Google云端硬盘启动Appmaker文档批准 [英] Initiate Appmaker Document Approval from Google Drive

查看:98
本文介绍了从Google云端硬盘启动Appmaker文档批准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已根据需要在Appmaker中自定义了文档管理系统模板.现在,我不再需要每次都去Appmaker进行审批,而是要提供从Google云端硬盘启动工作流程的功能.因此,用户可以直接从Google云端硬盘选择要审批的文件.

I've customized Document Management System template in Appmaker as per my needs. Now instead of going to Appmaker every time to initiate an approval I want to provide functionality to initiate the workflow from Google Drive.So users can select file for Approval directly from Google Drive.

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

My question is is there any Rest call or something via which I can initiate DMS workflow from Third party app?

推荐答案

好吧,我找到了实现结果的出路.

Well I found a way out to achieve the result.

步骤:

  1. Drive API提供了一种在Google云端硬盘的打开方式"菜单中添加您的应用的方法.
  2. 因此,我创建了我的自定义应用并进行了部署.该应用程序将仅从Google云端硬盘打开方式"菜单中接收参数,并将其传递给Appmaker文档批准系统.
  3. 在Appmaker创建请求页面中,如果请求包含这些参数,则进行解析;如果是,则使用这些参数选择文件.
  4. 这样,我的用户可以从Google云端硬盘启动文档批准工作流程.

参考文献:

  1. 如何在Google云端硬盘中添加/列出您的应用

分步视频指南来创建和发布您的应用

代码:

  1. 打开方式"应用代码,用于将用户从Google云端硬盘重定向到Appmaker.

code.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);
}

  1. 在文档"工作流程的创建请求"页面中,将事件添加到onAttach()方法.写下面的函数,
  1. In Document workflow 'Create Request' page, add event to onAttach() method. Write below function,

//客户端

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;
  });
}

这篇关于从Google云端硬盘启动Appmaker文档批准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆