Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法使用谷歌图表API的POST方法通过谷歌应用程序脚本获取二维码图像?_Post_Google Apps Script_Charts_Google Visualization_Qr Code - Fatal编程技术网

有没有办法使用谷歌图表API的POST方法通过谷歌应用程序脚本获取二维码图像?

有没有办法使用谷歌图表API的POST方法通过谷歌应用程序脚本获取二维码图像?,post,google-apps-script,charts,google-visualization,qr-code,Post,Google Apps Script,Charts,Google Visualization,Qr Code,我正在使用谷歌脚本生成活动的门票,门票中包含一个二维码,该二维码指向预先填充的谷歌表单链接。由于它是预填充的,字符串相当长,用于创建二维码的Google Charts API不会接受使用GET请求的那么长的文本字符串,但是我找不到任何关于如何将POST请求编码到应用程序脚本的文档。如何在应用程序脚本中生成POST请求,以返回二维码图像,然后将其插入文档 我已经尝试了GET请求,它在将URL编码为QR码之前将其截断。这让我看到了谷歌表单,但不是链接生成的预填充版本(谷歌方面非常聪明,让它在一个仍然

我正在使用谷歌脚本生成活动的门票,门票中包含一个二维码,该二维码指向预先填充的谷歌表单链接。由于它是预填充的,字符串相当长,用于创建二维码的Google Charts API不会接受使用GET请求的那么长的文本字符串,但是我找不到任何关于如何将POST请求编码到应用程序脚本的文档。如何在应用程序脚本中生成POST请求,以返回二维码图像,然后将其插入文档

我已经尝试了GET请求,它在将URL编码为QR码之前将其截断。这让我看到了谷歌表单,但不是链接生成的预填充版本(谷歌方面非常聪明,让它在一个仍然提供可用URL的地方截断字符串,但这是另一天的事…)

我还尝试了HtmlService,使用POST方法以HTML形式呈现QR代码,该HTML表单在加载该HTML时自动提交。如果我使用showSidebar(),这将在一个新选项卡中打开图像,但我还不知道如何返回该图像以便将其插入文档中

我还尝试用HTML创建一个blob,然后将该blob保存为PNG,但根据我所做的研究,.getAs()方法在转换HTML时不呈现图像

renderQR函数:

function renderQR(inputUrl) {
  var html = HtmlService.createTemplateFromFile('QREncode.html');
  html.url = inputUrl;  
  var rendered = html.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME)
    .setHeight(300)
    .setWidth(300);
 return rendered;   
}
QREncode.html文件:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script type='application/javascript'>
    // Send the POST when the page is loaded,
    // which will replace this whole page with the retrieved chart.
    function loadGraph() {
      var frm = document.getElementById('post_form');
      if (frm) {
       frm.submit();
      }
    }
    </script>
  </head>
  <body onload="loadGraph()">
    <form action='https://chart.googleapis.com/chart' method='POST' id='post_form'>
       <input type='hidden' name='cht' value='qr' />
      <input type='hidden' name='chl' value='<?= url ?>' />
      <input type='hidden' name='chs' value='300x300' />
      <input type='submit'/>
    </form>    
  </body>
</html>

//加载页面时发送帖子,
//这将用检索到的图表替换整个页面。
函数loadGraph(){
var frm=document.getElementById('post_form');
if(frm){
frm.submit();
}
}

您需要在应用程序脚本中获取二维码,而不是在浏览器中获取二维码:

  var imageData = UrlFetchApp.fetch('https://chart.googleapis.com/chart', {
    'method' : 'post',
    'payload' : {
      'cht': 'qr',
      'chl': 'https://google.com',
      'chs': '300x300'
  }}).getContent();

我以为信息图表是今年3月关闭的,我没听说过。无论如何,它还在工作。我就是不能以对我有用的形式得到输出。哦,我明白了。是的,但该功能似乎已经被应用到了图表服务中。事实上,Google Image Charts已被弃用,并于3月份被关闭,您可能希望检查免费和符合api的替代方案,就像这样做了!!非常感谢你!我不得不删除.getContent()方法以返回图像本身而不是数组数据,但这解决了它!对于希望在google drive中另存为图像的任何人
var imageData=UrlFetchApp.fetch('chart.googleapis.com/chart',{'method':'post','payload':{'cht':'qr','chl':'google.com','chs':'300x300'});让fileId=DriveApp.createFile(imageData).setName('qrCode.png').getId();DriveApp.getFileById(fileId).moveTo(您的文件夹ID)。希望有帮助