Javascript 有人让twilio授权工作了吗?
在Node SDK的twilio文档中,我遇到了一种授权twilio请求的方法:Javascript 有人让twilio授权工作了吗?,javascript,twilio,twilio-api,Javascript,Twilio,Twilio Api,在Node SDK的twilio文档中,我遇到了一种授权twilio请求的方法: var express = require('express'), bodyParser = require('body-parser'), http = require('http'), path = require('path'), twilio = require('twilio'); var app = express(); app.use(bodyParser.urle
var express = require('express'),
bodyParser = require('body-parser'),
http = require('http'),
path = require('path'),
twilio = require('twilio');
var app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
// Twilio request authentication
app.post('/twiml', function(req, res) {
if (twilio.validateExpressRequest(req, 'YOUR_TWILIO_AUTH_TOKEN')) {
var resp = new twilio.TwimlResponse();
resp.say('express sez - hello twilio!');
res.type('text/xml');
res.send(resp.toString());
}
else {
res.status(403).send('you are not twilio. Buzz off.');
}
});
// Start an HTTP server with this Express app
app.listen(process.env.PORT || 3000);
但是,当我运行此命令时,twilio.validateExpressRequest
总是返回false。为什么呢?我如何让这个例子起作用?有没有人有在twilio中设置安全授权的经验
此外,我还将twilio auth标记更改为正确的标记。看起来正确。是否在本地运行,并使用ngrok进行隧道?您可能需要将URL作为选项对象提供。在这里查看源代码:我正在服务器上部署它。不知道我应该提供什么网址;文档在他们的示例中使用了heroku应用程序,用于更一般的用途,我也在阅读本文,似乎没有node的示例,而且twilio库似乎缺少一个名为validatory
twilio.validateExpressRequest的函数(res,'YOUR_twilio\u AUTH\u TOKEN',{url:'YOUR_heroku\u url'})
。很遗憾文档中没有节点示例,我将向团队提出。