2017-12-05 1 views
1

twilio 서비스에서 SMS를 가져 오려고하지만 계속이 오류가 발생합니다.twilio A '보낸 사람'전화 번호가 필요합니다 swift

요청 :

func SMSRequest(countryCode:String, phoneNumber: String) { 
     let accountSid = "ACc4d9785419f144412823ff2034660c3d" 
     let authToken = "a2293a42841f8999caa237er363" // changed 

     let phoneNumber = "+14243960339" 
     let toNumber = "+37378847884" 

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


     let parameters = [ 
      "From": phoneNumber, 
      "To": toNumber, 
      "Body":"Hi daddy" 
     ] 

     Alamofire.request(url!, method: .post, parameters: parameters, 
          encoding: JSONEncoding.default, headers: [:]).responseJSON { response in 
          let response = String(describing: response.result.ifFailure({ 
           print(response) 
           if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {print("Data: \(utf8Text)")} 
          })) 


     } 
    } 

오류 :

<TwilioResponse><RestException><Code>21603</Code><Message>A 'From' phone number is required.</Message><MoreInfo>https://www.twilio.com/docs/errors/21603</MoreInfo><Status>400</Status></RestException></TwilioResponse> 

All the credentials I get from here

솔루션 : 사용 UTF8 인코딩.

+0

질문에 해결책을 추가하지 마십시오. 대답으로 추가하십시오. 그런 식으로 사람들은 당신이 그것을 풀 었음을 알게되고 장래에 다른 사람들을위한 좋은 참고 자료가됩니다. (또한 작동하도록 변경 한 코드를 표시하십시오.) – Fogmeister

답변

0

개발자 전도사 Twilio가 여기 있습니다.

문제를 해결했지만 근본적으로 안전하지 않은 응용 프로그램을 작성하고 있다는 점에 유의해야합니다. 나는 this comment on your other question을 남겨 뒀다. 그러나 나는 또한 그것을 여기에서 지적 할 필요가있다.

네이티브 응용 프로그램에서 직접 Twilio API에 대한 요청을하지 않는 것이 좋습니다. 이렇게하려면 어딘가에 응용 프로그램에 계정 SID 및 인증 토큰을 저장하거나 검색해야합니다. 이렇게하면 악의적 인 공격자가 사용자의 자격 증명에 액세스하여 Twilio 계정을 악용 할 수 있습니다.

실제로는 Eavesdropper vulnerability and was written about earlier this year으로 알려져 있습니다.

대신 웹 응용 프로그램을 만들고 거기에서 API 요청을 보내는 것이 좋습니다. 여기에서 수행하는 방법에 대한 블로그 게시물이 있습니다. https://www.twilio.com/blog/2016/11/how-to-send-an-sms-from-ios-in-swift.html

관련 문제