VB.NET Requires Chilkat v11.0.0+
VB.NET
Constant Contact V3: Read every page of list members
See more Constant Contact Examples
Filter the contacts collection with lists and a list ID. To query multiple lists together, supply their comma-separated IDs. Follow the returned cursor links and report the total after the last page. The default contacts query excludes deleted records. A list member can still have unsubscribed email permission. Authorize the app first and use the same credential store.
Constant Contact developer guide
Chilkat VB.NET Downloads
Dim success As Boolean = False
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim vault As New Chilkat.Secrets
vault.Location = "local_manager"
vault.AutoSplit = True
Dim entry As New Chilkat.JsonObject
entry.UpdateString("appName","ConstantContactV3")
entry.UpdateString("service","OAuth2")
entry.UpdateString("username","my-account")
Dim tokens As New Chilkat.JsonObject
Dim loaded As Boolean = vault.GetSecretJson(entry,tokens)
If (loaded <> True) Then
Debug.WriteLine("Run the desktop authorization example using this account and store.")
Exit Sub
End If
If (tokens.JsonTypeOf("access_token") <> 1) Then
Debug.WriteLine("The saved authorization has no access token.")
Exit Sub
End If
Dim http As New Chilkat.Http
http.RequireSslCertVerify = True
http.AuthToken = tokens.StringOf("access_token")
Dim resp As New Chilkat.HttpResponse
http.SetUrlVar("list","LIST_ID")
Dim url As New Chilkat.StringBuilder
url.Append("https://api.cc.email/v3/contacts?lists={$list}&limit=50")
Dim page As New Chilkat.JsonObject
Dim total As Integer = 0
While (url.Length > 0)
success = http.HttpNoBody("GET",url.GetAsString(),resp)
If ((success <> True) Or (resp.StatusCode <> 200)) Then
Debug.WriteLine("Expected HTTP 200. Received " & resp.StatusCode)
If (resp.StatusCode = 401) Then
Debug.WriteLine("Refresh the saved access token or authorize again.")
End If
Exit Sub
End If
success = page.Load(resp.BodyStr)
Dim count As Integer = page.SizeOfArray("contacts")
If ((success <> True) Or (count < 0)) Then
Debug.WriteLine("Expected a page of contacts.")
Exit Sub
End If
Dim i As Integer = 0
While (i < count)
page.I = i
Debug.WriteLine(page.StringOf("contacts[i].contact_id") & " " & page.StringOf("contacts[i].email_address.address"))
i = i + 1
End While
total = total + count
url.Clear()
If (page.JsonTypeOf("_links.next.href") = 1) Then
url.Append(page.StringOf("_links.next.href"))
' The documented cursor link is relative to api.cc.email.
If (url.StartsWith("/v3/contacts?",True) <> True) Then
Debug.WriteLine("Unexpected pagination link. Stopped before following it.")
Exit Sub
End If
url.Prepend("https://api.cc.email")
End If
End While
Debug.WriteLine("List members read: " & total)