【问题标题】:Twilio Function Calling Studio Rest API - Accountsid in correct errorTwilio 函数调用 Studio Rest API - Accountsid 错误
【发布时间】:2019-03-18 13:59:44
【问题描述】:

我正在从 Twilio 函数调用 Twilio Studio Flow Rest API。

以下是功能代码:

exports.handler = function(context, event, callback) {
   const request = require('request');  
   to = event.to;
   to = to.replace(/[()-.]/g, '');
   to = to.replace(/ /g, '');
   var postoptions = {  
   headers: {'AC' : 'b1xx'},       
   url:    'https://studio.twilio.com/v1/Flows/FWxxx8/Executions',  
        method: 'POST',  
        data: { 'from':  '+1814xxx',  
                'to': to 
            }  
        };

         request(postoptions, function(error, response, body){  
             callback(null, response);
         });
};

该函数一直说帐户 SID 和身份验证令牌不正确。但是 sid 和 token 是正确的。

我错过了什么?

【问题讨论】:

    标签: twilio twilio-functions


    【解决方案1】:

    当您在标头中传递 Account SID and auth token 时,您需要对它们进行“base64”编码。

    试试这样的:

    
    exports.handler = function (context, event, callback) {
        const request = require('request');
        to = event.to;
        to = to.replace(/[()-.]/g, '');
        to = to.replace(/ /g, '');
    
        var username = "AC";
        var password = "b1xx";
        var auth = "Basic " + new Buffer(username + ":" + password).toString("base64");
    
        var postoptions = {
            headers: { 'Authorization': auth },
            url: 'https://studio.twilio.com/v1/Flows/FWxxx8/Executions',
            method: 'POST',
            data: {
                'from': '+1814xxx',
                'to': to
            }
        };
    
        request(postoptions, function (error, response, body) {
            callback(null, response);
        });
    };
    
    

    【讨论】:

      猜你喜欢
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-27
      相关资源
      最近更新 更多