Xojo Plugin Requires Chilkat v11.0.0+
Xojo Plugin
List Twilio message history
See more Twilio Examples
List inbound and outbound messages, newest sent date first. Print the Message SID, direction, and status so you can distinguish incoming messages from outbound submissions and see their latest state.
Each response contains a messages array and a next_page_uri. Follow that URI until it is null. PageSize limits one response. Use credentials for the account whose history you want to read.
Chilkat Xojo Plugin Downloads
Dim success As Boolean
success = False
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim http As New Chilkat.Http
http.RequireSslCertVerify = True
http.BasicAuth = True
// Load the owning Account SID and an API key from application configuration.
Dim accountSid As String
accountSid = "YOUR_ACCOUNT_SID"
http.Login = "YOUR_API_KEY_SID"
http.Password = "YOUR_API_KEY_SECRET"
Dim url As New Chilkat.StringBuilder
success = url.Append("https://api.twilio.com/2010-04-01/Accounts/")
success = url.Append(accountSid)
success = url.Append("/Messages.json")
success = url.Append("?PageSize=50")
Dim resp As New Chilkat.HttpResponse
Dim reply As New Chilkat.JsonObject
Dim total As Int32
total = 0
Dim more As Boolean
more = True
While (more = True)
success = http.HttpNoBody("GET",url.GetAsString(),resp)
If (resp.StatusCode = 0) Then
System.DebugLog(http.LastErrorText)
Return
End If
Dim parsed As Boolean
parsed = reply.Load(resp.BodyStr)
If ((success <> True) Or (resp.StatusCode <> 200)) Then
System.DebugLog("HTTP " + Str(resp.StatusCode))
If ((parsed = True) And (reply.HasMember("code") = True)) Then
System.DebugLog("Twilio error " + Str(reply.IntOf("code")) + ": " + reply.StringOf("message"))
End If
Return
End If
If (parsed <> True) Then
System.DebugLog("Expected a JSON response.")
Return
End If
If (reply.JsonTypeOf("messages") <> 4) Then
System.DebugLog("Expected a messages array.")
Return
End If
Dim count As Int32
count = reply.SizeOfArray("messages")
Dim i As Int32
i = 0
While (i < count)
reply.I = i
System.DebugLog(reply.StringOf("messages[i].sid") + " " + reply.StringOf("messages[i].direction") + " " + reply.StringOf("messages[i].status"))
i = i + 1
Wend
total = total + count
// Twilio supplies a relative URI with the cursor and returns null on the last page.
If (reply.IsNullOf("next_page_uri") = True) Then
more = False
Else
If (reply.JsonTypeOf("next_page_uri") <> 1) Then
System.DebugLog("Expected a next-page URI or null.")
Return
End If
success = url.SetString("https://api.twilio.com")
success = url.Append(reply.StringOf("next_page_uri"))
End If
Wend
System.DebugLog("Messages found: " + Str(total))