appscript中基于html的对象引发格式错误的html错误
当我试图在应用程序脚本中显示content.text对象时,我遇到了一个问题,它返回了一个格式错误的html错误,特别是关于我的获取请求的获取appscript中基于html的对象引发格式错误的html错误,html,google-apps-script,output,Html,Google Apps Script,Output,当我试图在应用程序脚本中显示content.text对象时,我遇到了一个问题,它返回了一个格式错误的html错误,特别是关于我的获取请求的获取 https://www.cloudconnect.xxx... 我得到了我需要的一切,但是content.text位在应用程序脚本中抛出了一个格式错误的html。我想使用html并以正确的格式返回文档,并且相信我可以使用htmloutput正确地将此html解析为应用程序脚本,因为它需要清理,但我相信这是抛出格式错误的html对象的原因。如何在不转义h
https://www.cloudconnect.xxx...
我得到了我需要的一切,但是content.text位在应用程序脚本中抛出了一个格式错误的html。我想使用html并以正确的格式返回文档,并且相信我可以使用htmloutput正确地将此html解析为应用程序脚本,因为它需要清理,但我相信这是抛出格式错误的html对象的原因。如何在不转义html字符的情况下继续?我怎样才能正确地解析它?有人在这方面取得了成功吗
content.text的示例:
<body>
<!-- [DocumentBodyStart:a63392fa-f859-4513-867e-1f3d2714b006] -->
<div class=\"jive-rendered-content\">
<p>Hi,team!</p>
<p style=\"min-height: 8pt; padding: 0px;\"> </p>
<p>When executing attest () of SafetyNet Attestation API, apkPackageName is obtained as a parameter.</p>
<p>I ran this API several times.</p>
<p>As a result, the apkPackageName parameter was missing only once.</p>
<p>In all other execution results, the parameter apkPackageName is present and will not occur again.</p>
<p style=\"min-height: 8pt; padding: 0px;\"> </p>
<p>Why can't I get the apkPackageName when running the SafetyNet Attestation API on a device that has not been
tampered with?</p>
<p style=\"min-height: 8pt; padding: 0px;\"> </p>
<p>device : Kyocera 704KC</p>
<p style=\"min-height: 8pt; padding: 0px;\"> </p>
<p>Regards,</p>
</div><!-- [DocumentBodyEnd:a63392fa-f859-4513-867e-1f3d2714b006] -->
</body>
嗨,团队
在执行SafetyNet认证API的authentice()时,将获取apkPackageName作为参数
我多次运行这个API
因此,apkPackageName参数只丢失了一次
在所有其他执行结果中,参数apkPackageName存在并且不会再次出现
为什么在尚未安装的设备上运行SafetyNet认证API时无法获取apkPackageName
篡改
设备:京瓷704KC
问候,
有没有人对如何从这里开始有什么建议?我的目标是从content.text对象中获取文本,我可以在任何常规编辑器中看到该对象,但由于某种原因,在使用返回的html格式时不能在应用程序脚本中看到
代码.gs
function doGet(request) {
return HtmlService.createTemplateFromFile('Page').evaluate();
}
function include(filename) {
var finalRequest = UrlFetchApp.fetch('https://www.cloudconnect.xxx...');
var data = finalRequest.toString().replace("throw 'allowIllegalResourceCall is false.';", "").trim();
data = JSON.parse(data);
var returnedData = [];
for(var i in data.list){
var content = data.list[i];
var content_subject = JSON.stringify(content.subject);
var content_text = JSON.stringify(content.content.text);
returnedData.push(content_subject + "<br />" + "<br />" + textBody(content_text));
}
return returnedData;
}
function textBody(content){ // <-- where the error throws on the content_text object
return HtmlService.createHtmlOutput(content);
}
var entityMap = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": ''',
'/': '/',
'`': '`',
'=': '='
};
function escapeHtml(string) {
return String(string).replace(/[&<>"'`=\/]/g, function (s) {
return entityMap[s];
});
}
function myFunction() {
Logger.log(HtmlService
.createTemplateFromFile('Page')
.getCode());
}
function doGet(request) {
return HtmlService.createTemplateFromFile('Page').evaluate();
}
function include(filename) {
var finalRequest = UrlFetchApp.fetch('https://www.cloudconnect.xxx....');
var data = finalRequest.toString().replace("throw 'allowIllegalResourceCall is false.';", "").trim();
data = JSON.parse(data);
var returnedData = [];
for(var i in data.list){
var content = data.list[i];
var contentSubject = JSON.stringify(content.subject);
var contentText = JSON.stringify(content.content.text);
returnedData.push(contentSubject + "<br/>" + "<br/>");
var fixedContent = escapeHtml(contentText);// fixes the malformed Html error
var ui = HtmlService.createHtmlOutput(fixedContent);//the attempt to read the onlick event and load the content text - but it throws the error: Exception: Cannot call SpreadsheetApp.getUi() from this context. (line 21, file "Code")
SpreadsheetApp.getUi().showModelessDialog(ui);
Logger.log("returnedData is: " + returnedData);
}
return returnedData;
}
var entityMap = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": ''',
'/': '/',
'`': '`',
'=': '='
};
function escapeHtml(string) {
return String(string).replace(/[&<>"'`=\/]/g, function (s) {
return entityMap[s];
});
}
function myFunction() {
Logger.log(HtmlService
.createTemplateFromFile('Page')
.getCode());
}
//function contentBody(responseContent){ <-- realized I can't do this from a custom function
//var html = responseContent;
//var ui = HtmlService.createHtmlOutput(html);
//SpreadsheetApp.getUi().showModelessDialog(ui);
//}
函数doGet(请求){
返回HtmlService.createTemplateFromFile('Page').evaluate();
}
函数包括(文件名){
var finalRequest=UrlFetchApp.fetch('https://www.cloudconnect.xxx...');
var data=finalRequest.toString().replace(“throw'allowIllegalResourceCall为false”。;”,“”)。trim();
data=JSON.parse(数据);
var returnedData=[];
for(data.list中的var i){
var内容=数据列表[i];
var content_subject=JSON.stringify(content.subject);
var content_text=JSON.stringify(content.content.text);
returnedData.push(content_subject+”
“+”
“+textBody(content_text));
}
返回返回的数据;
}
函数textBody(content){/此功能:
function htmltest() {
var html='<body><!--[DocumentBodyStart:a63392fa-f859-4513-867e-1f3d2714b006]--><div class="jive-rendered-content"><p>Hi,team!</p><p style="min-height:8pt;padding:0px;"> </p><p>When executing at test() of Safety NetAttestationAPI, apkPackageName is obtained as a parameter.</p><p>I ran this API several times.</p><p>As a result,the apkPackageName parameter was missing only once.</p><p>In all other execution results,the parameter apkPackageName is present and will not occur again.</p><p style="min-height:8pt;padding:0px;"> </p><p>Whycan\'t I get the apkPackageName when running the Safety NetAttestation API on a device that has not been tampered with?</p><p style="min-height:8pt;padding:0px;"> </p><p>device:Kyocera704KC</p><p style="min-height:8pt;padding:0px;"> </p><p>Regards,</p></div><!--[DocumentBodyEnd:a63392fa-f859-4513-867e-1f3d2714b006]--></body>';
var ui=HtmlService.createHtmlOutput(html).setHeight(500);
SpreadsheetApp.getUi().showModelessDialog(ui, "HTML Test");
}
函数htmltest(){
var html='Hi,team!我多次运行此API。
因此,apkPackageName参数只丢失了一次。在所有其他执行结果中,参数apkPackageName存在并且不会再次出现。 ;
在未被篡改的设备上运行安全NetateStation API时,为什么我不能获得apkPackageName?&160;
设备:Kyocera704KC;
var ui=HtmlService.createHtmlOutput(html).setHeight(500);
SpreadsheetApp.getUi().showModelessDialog(ui,“HTML测试”);
}
这是我运行它时得到的结果
是否有任何原因让您在HTML内容中转义双引号。text
?能否添加您得到的确切错误?我最初使用了这个转义HTML函数,但现在不使用它。我最初将它用于subjects对象,但不需要它。嘿,Raserhin,返回的错误是:异常:格式错误的HTML c内容:“(第21行,文件“代码”)不幸的是,它没有返回对HtmlService.createHtmlOutput的调用:异常:格式错误的HTML内容:”。(第21行,文件“代码”)当我运行它时,就像我写的一样。它的工作原理如对话框中所示。也许你没有意识到,编辑了字符串中的所有错误。旧字符串根本不起作用。我很好奇你是如何做到这一点的……我用你的建议更新了我的代码,并返回了“异常:无法调用SpreadsheetApp.getUi()从这个上下文中。(第21行,文件“代码”)…这是有意义的,只是不确定如何继续。哪一行是第21行?嘿,库珀!第21行是对以下内容的调用:“SpreadsheetApp.getUi().showModelessDialog(ui);”
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<?!= include('Stylesheet'); ?>
<script>
var responseSubject;
var responseContent;
function displaySubjects(responseSubject) {
document.getElementById('output').addEventListener('click', getContentBody).innerHTML = responseSubject;
}
google.script.run.withFailureHandler(displaySubjects).withSuccessHandler(displaySubjects).include();
//function displayContentText(responseContent){
//document.getElementById('projection').innerHTML = responseContent;
//}
//google.script.run.withFailureHandler(displayContentText).withSuccessHandler(displayContentText).contentBody();
</script>
</head>
<body>
<p id = "output"></p>
<p id = "projection"></p>
</body>
</html>
function htmltest() {
var html='<body><!--[DocumentBodyStart:a63392fa-f859-4513-867e-1f3d2714b006]--><div class="jive-rendered-content"><p>Hi,team!</p><p style="min-height:8pt;padding:0px;"> </p><p>When executing at test() of Safety NetAttestationAPI, apkPackageName is obtained as a parameter.</p><p>I ran this API several times.</p><p>As a result,the apkPackageName parameter was missing only once.</p><p>In all other execution results,the parameter apkPackageName is present and will not occur again.</p><p style="min-height:8pt;padding:0px;"> </p><p>Whycan\'t I get the apkPackageName when running the Safety NetAttestation API on a device that has not been tampered with?</p><p style="min-height:8pt;padding:0px;"> </p><p>device:Kyocera704KC</p><p style="min-height:8pt;padding:0px;"> </p><p>Regards,</p></div><!--[DocumentBodyEnd:a63392fa-f859-4513-867e-1f3d2714b006]--></body>';
var ui=HtmlService.createHtmlOutput(html).setHeight(500);
SpreadsheetApp.getUi().showModelessDialog(ui, "HTML Test");
}