Content management system 获取并在html页面中显示Google文档正文

Content management system 获取并在html页面中显示Google文档正文,content-management-system,google-apps-script,google-docs-api,Content Management System,Google Apps Script,Google Docs Api,是否可以检索Google文档的内容并将其显示在html页面的div中?如果是这样的话,下面这个简单的例子中实现“魔法”的正确方法是什么 检索并显示Google文档正文的脚本或链接。 在上面,您可以假设 html由GoogleDrive托管服务 对Google文档的引用是静态的 无需从公共html页面中编辑文档(即在该上下文中是只读的)。 我已经通读了应用程序脚本文档,看起来文档服务和内容服务的某种组合似乎是可能的。例如,Document Service有getBody()和copy()方法,

是否可以检索Google文档的内容并将其显示在html页面的div中?如果是这样的话,下面这个简单的例子中实现“魔法”的正确方法是什么


检索并显示Google文档正文的脚本或链接。
在上面,您可以假设

  • html由GoogleDrive托管服务
  • 对Google文档的引用是静态的
  • 无需从公共html页面中编辑文档(即在该上下文中是只读的)。
  • 我已经通读了应用程序脚本文档,看起来文档服务和内容服务的某种组合似乎是可能的。例如,Document Service有getBody()和copy()方法,但不清楚这些调用返回的对象是否可以作为html呈现为WYSIWYG以插入html容器

    背景:我正在尝试为一个小型非营利组织实施一个安全易用的CMS。我已经制作了一个网站框架的原型 在谷歌硬盘上。到目前为止,它看起来很有希望,但是改变需要能够编辑html。我们有很多人可以在类似文字处理器的环境中创建内容,但包括我在内的只有几人 谁能处理HTML/CSS/JQuery/AppsScript

    如果我能专注于整个框架,让其他人为我更新内容 这将是一场巨大的胜利。基本上,如果他们能够编辑Google文档,然后手动重新加载网页以查看结果,我会非常高兴


    我知道CMS有很多方法,但现在,我感兴趣的是探索一个纯Google Docs/Google Drive解决方案。

    您可以通过使用urlFetch调用驱动API来获取Google doc的原始html内容,下面是它的工作原理

    var id='Doc Very Long id Here';
    var url='1〕https://docs.google.com/feeds/';
    var doc=UrlFetchApp.fetch(url+'download/documents/Export?exportFormat=html&format=html&id='+id,
    googleOAuth((“文档”,url)).getContentText();
    //变量doc是可以使用的HTML内容
    googleOAuth函数(名称、范围){
    var oAuthConfig=UrlFetchApp.addOAuthService(名称);
    oAuthConfig.setRequestTokenUrl(“https://www.google.com/accounts/OAuthGetRequestToken?scope=“+范围);
    oAuthConfig.setAuthorizationUrl(“https://www.google.com/accounts/OAuthAuthorizeToken");
    oAuthConfig.setAccessTokenUrl(“https://www.google.com/accounts/OAuthGetAccessToken");
    oAuthConfig.setConsumerKey('anonymous');
    oAuthConfig.setConsumerCret('anonymous');
    返回{oAuthServiceName:name,oAuthUseToken:“始终”};
    }
    
    还有一个由Romain Vialard创建的库,它被称为DocsListedExtended,提供了一系列不错的扩展


    编辑:编辑后:

    不能像那样使用它,在Web应用程序中呈现HTML内容,请使用下面的示例以及完整的代码和:

    函数doGet(){
    变量id='1el3dptp1sukdjlkxh8plf0zj-qm0drI7KbytroVrNU';
    var url='1〕https://docs.google.com/feeds/';
    var doc=UrlFetchApp.fetch(url+'download/documents/Export?exportFormat=html&format=html&id='+id,googleOAuth(('docs',url)).getContentText();
    返回HtmlService.createHtmlOutput(doc);
    }
    //变量doc是可以使用的HTML内容
    googleOAuth函数(名称、范围){
    var oAuthConfig=UrlFetchApp.addOAuthService(名称);
    oAuthConfig.setRequestTokenUrl(“https://www.google.com/accounts/OAuthGetRequestToken?scope=“+范围);
    oAuthConfig.setAuthorizationUrl(“https://www.google.com/accounts/OAuthAuthorizeToken");
    oAuthConfig.setAccessTokenUrl(“https://www.google.com/accounts/OAuthGetAccessToken");
    oAuthConfig.setConsumerKey('anonymous');
    oAuthConfig.setConsumerCret('anonymous');
    返回{oAuthServiceName:name,oAuthUseToken:“始终”};
    }
    
    您可以通过使用urlFetch调用驱动API来获取google文档的原始html内容,下面是它的工作原理

    var id='Doc Very Long id Here';
    var url='1〕https://docs.google.com/feeds/';
    var doc=UrlFetchApp.fetch(url+'download/documents/Export?exportFormat=html&format=html&id='+id,
    googleOAuth((“文档”,url)).getContentText();
    //变量doc是可以使用的HTML内容
    googleOAuth函数(名称、范围){
    var oAuthConfig=UrlFetchApp.addOAuthService(名称);
    oAuthConfig.setRequestTokenUrl(“https://www.google.com/accounts/OAuthGetRequestToken?scope=“+范围);
    oAuthConfig.setAuthorizationUrl(“https://www.google.com/accounts/OAuthAuthorizeToken");
    oAuthConfig.setAccessTokenUrl(“https://www.google.com/accounts/OAuthGetAccessToken");
    oAuthConfig.setConsumerKey('anonymous');
    oAuthConfig.setConsumerCret('anonymous');
    返回{oAuthServiceName:name,oAuthUseToken:“始终”};
    }
    
    还有一个由Romain Vialard创建的库,它被称为DocsListedExtended,提供了一系列不错的扩展


    编辑:编辑后:

    不能像那样使用它,在Web应用程序中呈现HTML内容,请使用下面的示例以及完整的代码和:

    函数doGet(){
    变量id='1el3dptp1sukdjlkxh8plf0zj-qm0drI7KbytroVrNU';
    var url='1〕https://docs.google.com/feeds/';
    var doc=UrlFetchApp.fetch(url+'download/documents/Export?exportFormat=html&format=html&id='+id,googleOAuth(('docs',url)).getContentText();
    返回HtmlService.createHtmlOutput(doc);
    }
    //变量doc是可以使用的HTML内容
    googleOAuth函数(名称、范围){
    var oAuthConfig=UrlFetchApp.addOAuthService(名称);
    oAuthConfig.setRequestTokenUrl(“http