Visual Basic 6.0 Requires Chilkat v11.0.0+
Visual Basic 6.0
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 Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim vault As New ChilkatSecrets
vault.Location = "local_manager"
vault.AutoSplit = 1
Dim entry As New ChilkatJsonObject
success = entry.UpdateString("appName","ConstantContactV3")
success = entry.UpdateString("service","OAuth2")
success = entry.UpdateString("username","my-account")
Dim tokens As New ChilkatJsonObject
Dim loaded As Long
loaded = vault.GetSecretJson(entry,tokens)
If (loaded <> 1) Then
Debug.Print "Run the desktop authorization example using this account and store."
Exit Sub
End If
If (tokens.JsonTypeOf("access_token") <> 1) Then
Debug.Print "The saved authorization has no access token."
Exit Sub
End If
Dim http As New ChilkatHttp
http.RequireSslCertVerify = 1
http.AuthToken = tokens.StringOf("access_token")
Dim resp As New ChilkatHttpResponse
success = http.SetUrlVar("list","LIST_ID")
Dim url As New ChilkatStringBuilder
success = url.Append("https://api.cc.email/v3/contacts?lists={$list}&limit=50")
Dim page As New ChilkatJsonObject
Dim total As Long
total = 0
Do While (url.Length > 0)
success = http.HttpNoBody("GET",url.GetAsString(),resp)
If ((success <> 1) Or (resp.StatusCode <> 200)) Then
Debug.Print "Expected HTTP 200. Received " & resp.StatusCode
If (resp.StatusCode = 401) Then
Debug.Print "Refresh the saved access token or authorize again."
End If
Exit Sub
End If
success = page.Load(resp.BodyStr)
Dim count As Long
count = page.SizeOfArray("contacts")
If ((success <> 1) Or (count < 0)) Then
Debug.Print "Expected a page of contacts."
Exit Sub
End If
Dim i As Long
i = 0
Do While (i < count)
page.I = i
Debug.Print page.StringOf("contacts[i].contact_id") & " " & page.StringOf("contacts[i].email_address.address")
i = i + 1
Loop
total = total + count
url.Clear
If (page.JsonTypeOf("_links.next.href") = 1) Then
success = url.Append(page.StringOf("_links.next.href"))
' The documented cursor link is relative to api.cc.email.
If (url.StartsWith("/v3/contacts?",1) <> 1) Then
Debug.Print "Unexpected pagination link. Stopped before following it."
Exit Sub
End If
success = url.Prepend("https://api.cc.email")
End If
Loop
Debug.Print "List members read: " & total