Google Apps脚本进行HTTP POST [英] Google Apps Script make HTTP POST

查看:93
本文介绍了Google Apps脚本进行HTTP POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Google Apps脚本进行HTTP POST. 我发现的文档很少,也许有人可以帮忙吗?

I would like to make an HTTP POST using google apps script. I have found very little documentation on this, maybe someone could kindly help?

HTTP POST将发送到名为"Twilio"的服务:

The HTTP POST will be to a service called 'Twilio':

https://www.twilio.com/docs/api/rest/发送短信

页面上说我在POST中只需要三个参数:

The page says I only need three parameters in my POST:

  • 发件人"号码
  • 收件人"号码
  • 身体"

我希望HTTP Post能够调用Twilio发送短信.

I am hoping that the HTTP Post will invoke Twilio to send an sms.

最后,我想从Google电子表格中获取这些参数.我可以自己做,因为我对Apps脚本相当满意,但是我从来没有做过HTTP POST,所以现在(为了简单起见),我自己将这些参数键入代码中.

In the end I want to get these parameters from a google spreadsheet. I can do that myself as I'm fairly comfortable with Apps Script but I've never done an HTTP POST, so for now (and for the sake of simplicity) I'll just type these parameters into the code myself.

如果有人知道如何执行此操作,或者使用Apps Script进行任何类型的HTTP POST,请让我知道-我已经花费了数小时试图弄清楚这一点!

If anyone knows how to do this, or make any sort of HTTP POST with Apps Script, please let me know - I've spent hours trying to figure this one out!

推荐答案

我设法做到了,这是代码:

i managed to do it, here's the code:

var url = "https://api.twilio.com/2010-04-01/Accounts/ ...account.SID... /SMS/Messages.json";
var options = {
"method": "post",
"headers": {
"Authorization": "Basic " + Utilities.base64Encode(" ...account.SID... : ...auth.token... ")
},
"payload": {
"From": "+12025551212",
"To": "+14155551212",
"Body": "Test from Google Apps Script"
}
};
var response = UrlFetchApp.fetch(url, options);

这篇关于Google Apps脚本进行HTTP POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆