Xojo Plugin Requires Chilkat v11.0.0+
Xojo Plugin
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 Xojo Plugin Downloads
Dim success As Boolean
success = 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
success = entry.UpdateString("appName","ConstantContactV3")
success = entry.UpdateString("service","OAuth2")
success = entry.UpdateString("username","my-account")
Dim tokens As New Chilkat.JsonObject
Dim loaded As Boolean
loaded = vault.GetSecretJson(entry,tokens)
If (loaded <> True) Then
System.DebugLog("Run the desktop authorization example using this account and store.")
Return
End If
If (tokens.JsonTypeOf("access_token") <> 1) Then
System.DebugLog("The saved authorization has no access token.")
Return
End If
Dim http As New Chilkat.Http
http.RequireSslCertVerify = True
http.AuthToken = tokens.StringOf("access_token")
Dim resp As New Chilkat.HttpResponse
success = http.SetUrlVar("list","LIST_ID")
Dim url As New Chilkat.StringBuilder
success = url.Append("https://api.cc.email/v3/contacts?lists={$list}&limit=50")
Dim page As New Chilkat.JsonObject
Dim total As Int32
total = 0
While (url.Length > 0)
success = http.HttpNoBody("GET",url.GetAsString(),resp)
If ((success <> True) Or (resp.StatusCode <> 200)) Then
System.DebugLog("Expected HTTP 200. Received " + Str(resp.StatusCode))
If (resp.StatusCode = 401) Then
System.DebugLog("Refresh the saved access token or authorize again.")
End If
Return
End If
success = page.Load(resp.BodyStr)
Dim count As Int32
count = page.SizeOfArray("contacts")
If ((success <> True) Or (count < 0)) Then
System.DebugLog("Expected a page of contacts.")
Return
End If
Dim i As Int32
i = 0
While (i < count)
page.I = i
System.DebugLog(page.StringOf("contacts[i].contact_id") + " " + page.StringOf("contacts[i].email_address.address"))
i = i + 1
Wend
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?",True) <> True) Then
System.DebugLog("Unexpected pagination link. Stopped before following it.")
Return
End If
success = url.Prepend("https://api.cc.email")
End If
Wend
System.DebugLog("List members read: " + Str(total))