【问题标题】:How to fix 404 "The requested resource /2010-04-01/Accounts//SMS/Messages.json" not found error in Twilio-Connector in Ballerina如何在 Ballerina 的 Twilio-Connector 中修复 404“请求的资源 /2010-04-01/Accounts//SMS/Messages.json”错误
【发布时间】:2019-01-08 08:50:19
【问题描述】:

我正在使用芭蕾舞演员创建客户注册休息服务,与此相关的用例是当客户成功注册时,我需要向客户发送短信。当我使用芭蕾舞演员中的 Twilio 连接器发送短信时,我得到以下错误。

404 Not Found-:The requested resource /2010-04-01/Accounts//SMS/ 
Messages.json was not found.        

下面显示了与 Twilio 集成相关的代码,

import wso2/twilio;
twilio:Client twilioClient = new({
    accountSId: config:getAsString(TWILIO_ACCOUNT_SID),
    authToken: config:getAsString(TWILIO_AUTH_TOKEN)
});

我也在 ballerina.conf 文件中包含了 Twilio-Sid 和 Auth Token。下面显示了我编写的通过 Twilio-connector 发送短信的函数

function sendSmsToCustomers(string mobile) returns boolean {

    boolean isSuccess= false;
    string toMobile = mobile;
    string messageBody = config:getAsString(TWILIO_MESSAGE);
    string fromMobile = config:getAsString(TWILIO_FROM_MOBILE);
    string message = messageBody;
    var response = twilioClient->sendSms(fromMobile, toMobile,  message);
   if (response is twilio:SmsResponse) {
        if (response.sid != EMPTY_STRING) {
            log:printDebug("Twilio Connector -> SMS successfully sent to " + toMobile);
            return true;
        }
    } else {
        log:printDebug("Twilio Connector -> SMS failed sent to " + toMobile);
        log:printError(<string>response.detail().message);
    }
    return isSuccess;
}

预期的输出应该是向提供的手机号码(toMobile)发送一条短信

【问题讨论】:

    标签: twilio-api ballerina


    【解决方案1】:

    这里的问题是 ballerina.conf 文件中没有读取 TWILIO_ACCOUNT_SIDballerina.conf 文件应具有如下配置属性,以便与您的代码匹配。

    TWILIO_ACCOUNT_SID="your_account_sid"
    TWILIO_AUTH_TOKEN="your_auth_token"
    TWILIO_MESSAGE="your_message"
    TWILIO_FROM_MOBILE="your_from_mobile_number"
    

    【讨论】:

    • 我在 ballerina.conf 文件中输入了配置,即使我删除了凭据,我也会收到不同的响应,如“401 Unauthorized - : Authentication Error - No credentials provided”。所以问题不在于它看起来的凭据,而是在访问他们的资源时。这就是为什么我得到“404 Not Found - : The requested resource /2010-04-01/Accounts//SMS/Messages.json was not found”错误。
    • 你能试试新的拉包吗?我最近修复了一个错误,但您可能不会收到此错误。请在执行以下命令后尝试您的代码。它将拉取最新的模块版本。 ballerina pull wso2/twilio
    • 是的,拉取最新模块版本后问题已解决。谢谢。
    【解决方案2】:

    我面临着类似的问题。 我在Twilio/Rest/Client.php 中发现了什么 构造函数需要用户名、密码和其他详细信息。

    公共函数 __construct(string $username = null, string $password = null, string $accountSid = null, string $region = null, HttpClient $httpClient = null , 数组 $environment = null)

    但是在用于库加载的 Twilio.php 中,它试图通过传递 SID 和 TOKEN 来创建 Client 对象。

    所以很可能是共享的库代码不正确或版本不同

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-25
      • 1970-01-01
      • 2014-01-06
      • 2015-10-30
      • 1970-01-01
      • 2021-06-21
      • 1970-01-01
      • 2014-04-27
      相关资源
      最近更新 更多