Alamofire request to twilio swift

↘锁芯ラ 提交于 2020-01-06 05:22:25

问题


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)
        }
    }

}

回答1:


Twilio developer evangelist here.

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.

This is actually known as the Eavesdropper vulnerability and was written about earlier this year.

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

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.



来源:https://stackoverflow.com/questions/47657336/alamofire-request-to-twilio-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!