我正在尝试使用twilio的HTTP端点发送WhatsApp消息,但失败并显示错误
{“代码”:21602,“消息”:“消息正文是必需的。”,“ more_info”:“ https://www.twilio.com/docs/errors/21602”,“状态”:400}
我没有故意将'content-type': 'application/x-www-form-urlencoded'
添加为URLFetchApp adds the same automatically。
function sampletTextMessage(){
var ACCOUNT_SID = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var ACCOUNT_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var options = {
"method" : "post",
'headers' : {
"Authorization" : "Basic " + Utilities.base64Encode(ACCOUNT_SID + ":" + ACCOUNT_TOKEN),
},
'payload' :{
'body' : 'Your Twilio code is 1238432',
'to' : 'whatsapp:+91XXXXXXXXX3',
'from': 'whatsapp:+1XXXXXXXXX6',
},
'muteHttpExceptions' : true
};
var url="https://api.twilio.com/2010-04-01/Accounts/" + ACCOUNT_SID + "/Messages.json";
var response = UrlFetchApp.fetch(url,options);
Logger.log(response);
}
答案 0 :(得分:3)
您的情况似乎有误,大写“收件人”,“发件人”和“正文”。
参考: How to Send SMS from a Google Spreadsheet
var payload = {
"To": to,
"Body" : body,
"From" : "YOURTWILIONUMBER"
};