Content management system 获取并在html页面中显示Google文档正文
是否可以检索Google文档的内容并将其显示在html页面的div中?如果是这样的话,下面这个简单的例子中实现“魔法”的正确方法是什么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文档正文的脚本或链接。
在上面,您可以假设
我知道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