Xojo Plugin Requires Chilkat v11.0.0+
Xojo Plugin
Send an SMS verification code with Twilio Verify
See more Twilio Examples
Live SMS. When a user requests a code, pass their phone number in E.164 format (for example, +12025550123) and select the SMS channel. Create a Verify Service in the Twilio Console first. Supply its VA service SID and an API key with access to that service. For a live test, use a phone you control. Messaging and verification charges may apply.
Twilio generates the code and sends it to the phone. A pending response means the application can prompt for the code. Save the returned VE verification SID with the user and phone number that initiated the request, then use it to check the code entered by the user.
Chilkat Xojo Plugin Downloads
Dim success As Boolean
success = False
// Assumes Chilkat is unlocked. See Global Unlock Sample.
// Obtain these credentials from the application's private configuration.
Dim http As New Chilkat.Http
http.RequireSslCertVerify = True
http.BasicAuth = True
http.Login = "YOUR_API_KEY_SID"
http.Password = "YOUR_API_KEY_SECRET"
// Both requests use the same Verify Service SID (VA...).
Dim url As New Chilkat.StringBuilder
success = url.Append("https://verify.twilio.com/v2/Services/")
success = url.Append("YOUR_VERIFY_SERVICE_SID")
success = url.Append("/Verifications")
Dim req As New Chilkat.HttpRequest
req.HttpVerb = "POST"
req.ContentType = "application/x-www-form-urlencoded"
// Supply the number the user asked to verify. AddParam encodes the leading plus sign.
req.AddParam "To","PHONE_NUMBER_IN_E164_FORMAT"
req.AddParam "Channel","sms"
Dim resp As New Chilkat.HttpResponse
success = http.HttpReq(url.GetAsString(),req,resp)
If (resp.StatusCode = 0) Then
System.DebugLog("No response from Twilio. Check connectivity and TLS settings.")
Return
End If
Dim result As New Chilkat.JsonObject
Dim parsed As Boolean
parsed = result.Load(resp.BodyStr)
If ((success <> True) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
System.DebugLog("Twilio returned HTTP " + Str(resp.StatusCode))
If ((parsed = True) And (result.JsonTypeOf("code") = 2)) Then
System.DebugLog("Twilio error code: " + Str(result.IntOf("code")))
End If
Return
End If
If ((parsed <> True) Or (result.JsonTypeOf("status") <> 1)) Then
System.DebugLog("Verification status missing from the response.")
Return
End If
Dim status As String
status = result.StringOf("status")
If (status <> "pending") Then
System.DebugLog("Verification status: " + status)
Return
End If
If ((result.JsonTypeOf("sid") <> 1) Or (result.StringOf("sid") = "")) Then
System.DebugLog("The pending response did not include a verification SID.")
Return
End If
// Save this SID with the pending attempt before prompting the user for the code.
System.DebugLog("Pending verification SID: " + result.StringOf("sid"))