google-apps-script - 在 UrlFetchApp.fetch(...) 中使用变量不起作用
问题描述
我想使用 Google App Script 让 Telegram Bot 在聊天中发布消息。当我使用这行代码时,效果很好:
var message = UrlFetchApp.fetch(url + "/sendMessage?chat_id=" + chat_id_Testgruppe + "&text=HelloWorld");
但是,如果我用这样的变量替换“HelloWorld”:
var body = threads[i].getMessages().pop().getPlainBody(); // Gets the message-String from a Gmail-Thread
var message = UrlFetchApp.fetch(url + "/sendMessage?chat_id=" + chat_id_Testgruppe + "&text=" + body);
然后我得到一个无效的参数错误,即使显示为 fetch 函数的非法参数的参数有效,如果我将它复制并粘贴到我的浏览器。
解决方案
我需要在我的变量上使用 encodeURIComponent() ,这解决了这个问题。
推荐阅读
- vba - 为什么 MsgBox 会弹出两次?
- node.js - Mongoose 字段验证无法正常工作
- reactjs - 反应原生转换 - 错误找不到预设“babel-preset-react-native-stage-0
- javascript - Angular 5 多路由模块
- sql - 将 DATE 插入 SQL 表时遇到问题
- javascript - 如何更改此缩小的 if 语句?
- php - PHP CLI 模式下的方框绘图字符和 CLS
- javascript - 带有“onclick”处理程序的 JavaScript innerHTML 操作
- wpf - 讲述人在扫描模式下读取隐藏元素
- c# - C# 如何使用我的 adaptername.GetPosition(“some string”)