Alamofire要求twilio迅速 [英] Alamofire request to twilio swift

查看:95
本文介绍了Alamofire要求twilio迅速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从twilio.com收到一条短信,但回复为零。有人可以说我在做什么错吗?

I'm trying to get an SMS from twilio.com but get nil in response. Can anyone say what I'm doing wrong?

class SMSVerificationService: NSObject {

    static let sharedInstance = SMSVerificationService()


    func SMSRequest(countryCode:String, phoneNumber: String) {
        let accountSid = "ACc4d9785419f144412823ff20as34660c3d"
        let authToken = "4wqecx41f8999caa23735da214" // changed :)

        let url = URL(string: "https://\(accountSid):\(authToken)@api.twilio.com/2010-04-01/Accounts\(accountSid)/Messages")
        print("url", url!)

        let parameters = [
            "To": "+37378847884",
            "From" : "+14243960339",
            "Body": "Hi daddy"
        ]
        Alamofire.request(url!, method: .post, parameters: parameters,
                          encoding: JSONEncoding.default, headers: [:]).responseJSON { response in
                            let response = String(describing: response.result.value)
                            print(response)
        }
    }

}


推荐答案

此处是Twilio开发人员的传播者。

Twilio developer evangelist here.

我们不建议您向Twilio API发出请求直接从您的本机应用程序。为此,您需要在某处的应用程序中存储或检索帐户SID和身份验证令牌。如果这样做,那么恶意攻击者可能会访问您的凭据并滥用您的Twilio帐户。

We do not recommend that you make requests to the Twilio API directly from your native application. To do so, you would need to store or retrieve your account SID and auth token in the application somewhere. If you do this, then a malicious attacker could get access to your credentials and abuse your Twilio account.

这实际上称为窃听者漏洞,并于今年初撰写。

相反,我们建议您创建一个Web应用程序并从那里发送API请求。这里有一篇有关如何执行此操作的博客文章:> https://www.twilio.com/blog/2016/11/how-to-send-an-sms-from-ios-in-swift.html

Instead we recommend that you create a web application and send the API requests from there. There is a blog post on how to do that here: https://www.twilio.com/blog/2016/11/how-to-send-an-sms-from-ios-in-swift.html

我注意到您的课程也称为 SMSVerificationService 。如果您想建立电话验证,那么我建议您看一下 Twilio验证API 可以为您完成很多工作。

I notice that your class is called SMSVerificationService too. If you are looking to build phone verification, then I recommend you take a look at the Twilio Verify API that does a lot of the work for you.

这篇关于Alamofire要求twilio迅速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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