Visual Basic 6.0 Requires Chilkat v11.0.0+
Visual Basic 6.0
PayPal: Decide when to renew an access token
See more PayPal Examples
Use the UTC request time and expires_in from the token example. Renew five minutes early. This is a cache decision; a revoked token can still receive HTTP 401 before its calculated expiry.
Chilkat Visual Basic 6.0 Downloads
' Read the metadata saved by Get a sandbox access token.
Dim timing As New ChilkatJsonObject
Dim issued As New CkDateTime
Dim loadedTiming As Long
loadedTiming = timing.LoadFile("paypal-token-timing.json")
If (loadedTiming <> 1) Then
Debug.Print "No timing metadata. Request a token."
Exit Sub
End If
Dim validTimestamp As Long
validTimestamp = issued.SetFromTimestamp(timing.StringOf("issued_at"))
If (validTimestamp <> 1) Then
Debug.Print "Invalid issue time. Request a token."
Exit Sub
End If
Dim now As New CkDateTime
success = now.SetFromCurrentSystemTime()
Dim age As Long
age = now.DiffSeconds(issued)
Dim lifetime As Long
lifetime = timing.IntOf("expires_in")
If ((age < 0) Or (lifetime <= 300) Or (age >= (lifetime - 300))) Then
Debug.Print "Request a new client-credentials token."
Exit Sub
End If
Debug.Print "Reuse the matching token from the credential store."