Twilio POST 请求在 iOS 上使用 Alamofire

Twilio POST request using Alamofire on iOS

我有这个 IBAction,它应该只是测试发送短信:

    let todosEndpoint: String = "https://api.twilio.com/2010-04-01/Accounts/\(ACCOUNT_SID)/Messages.json"
    let message = ["To": "+1555...5555", "From": "+555...5555", "Body": "Hello!"]
    for item in message {
        print(item)
    }

    Alamofire.request(todosEndpoint, method: .post, parameters: message, encoding: JSONEncoding.default)
        .authenticate(user: ACCOUNT_SID, password: ACCESS_TOKEN)
        .responseJSON { response in
            debugPrint(response)

    }

但是,我收到的回复是:

[Result]: SUCCESS: {
    code = 21603;
    message = "A 'From' phone number is required.";
    "more_info" = "https://www.twilio.com/docs/errors/21603";
    status = 400;
}

我确定我提供了正确的 phone 号码和身份验证,并且我已经使用 python 来测试使用我的 API 密钥和 phone 号码发送消息. 是我的字典结构有误还是什么? 感谢您的帮助!

此处为 Twilio 开发人员布道师。

我们不建议您 API 从您的应用程序直接调用 Twilio。您需要以某种方式在应用程序中包含您的帐户凭据,以便恶意攻击者可以反编译应用程序、提取您的详细信息并滥用您的 Twilio 帐户。

相反,我们建议您设置一个自己的服务器来保护凭据的安全,然后自己向该服务器发出请求。在 sending SMS messages on iOS with Twilio, Swift and Alamofire.

上查看此博客 post