VB.NET Requires Chilkat v11.0.0+
VB.NET
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 VB.NET Downloads
' Read the metadata saved by Get a sandbox access token.
Dim timing As New Chilkat.JsonObject
Dim issued As New Chilkat.CkDateTime
Dim loadedTiming As Boolean = timing.LoadFile("paypal-token-timing.json")
If (loadedTiming <> True) Then
Debug.WriteLine("No timing metadata. Request a token.")
Exit Sub
End If
Dim validTimestamp As Boolean = issued.SetFromTimestamp(timing.StringOf("issued_at"))
If (validTimestamp <> True) Then
Debug.WriteLine("Invalid issue time. Request a token.")
Exit Sub
End If
Dim now As New Chilkat.CkDateTime
now.SetFromCurrentSystemTime()
Dim age As Integer = now.DiffSeconds(issued)
Dim lifetime As Integer = timing.IntOf("expires_in")
If ((age < 0) Or (lifetime <= 300) Or (age >= (lifetime - 300))) Then
Debug.WriteLine("Request a new client-credentials token.")
Exit Sub
End If
Debug.WriteLine("Reuse the matching token from the credential store.")