AutoIt Requires Chilkat v11.0.0+
AutoIt
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 AutoIt Downloads
; Read the metadata saved by Get a sandbox access token.
$oTiming = ObjCreate("Chilkat.JsonObject")
$oIssued = ObjCreate("Chilkat.CkDateTime")
Local $bLoadedTiming = $oTiming.LoadFile("paypal-token-timing.json")
If ($bLoadedTiming <> True) Then
ConsoleWrite("No timing metadata. Request a token." & @CRLF)
Exit
EndIf
Local $bValidTimestamp = $oIssued.SetFromTimestamp($oTiming.StringOf("issued_at"))
If ($bValidTimestamp <> True) Then
ConsoleWrite("Invalid issue time. Request a token." & @CRLF)
Exit
EndIf
$oNow = ObjCreate("Chilkat.CkDateTime")
$oNow.SetFromCurrentSystemTime()
Local $iAge = $oNow.DiffSeconds($oIssued)
Local $iLifetime = $oTiming.IntOf("expires_in")
If (($iAge < 0) Or ($iLifetime <= 300) Or ($iAge >= ($iLifetime - 300))) Then
ConsoleWrite("Request a new client-credentials token." & @CRLF)
Exit
EndIf
ConsoleWrite("Reuse the matching token from the credential store." & @CRLF)