Classic ASP Requires Chilkat v11.0.0+
Classic ASP
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 Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
' Read the metadata saved by Get a sandbox access token.
set timing = Server.CreateObject("Chilkat.JsonObject")
set issued = Server.CreateObject("Chilkat.CkDateTime")
loadedTiming = timing.LoadFile("paypal-token-timing.json")
If (loadedTiming <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "No timing metadata. Request a token.") & "</pre>"
Response.End
End If
validTimestamp = issued.SetFromTimestamp(timing.StringOf("issued_at"))
If (validTimestamp <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid issue time. Request a token.") & "</pre>"
Response.End
End If
set now = Server.CreateObject("Chilkat.CkDateTime")
success = now.SetFromCurrentSystemTime()
age = now.DiffSeconds(issued)
lifetime = timing.IntOf("expires_in")
If ((age < 0) Or (lifetime <= 300) Or (age >= (lifetime - 300))) Then
Response.Write "<pre>" & Server.HTMLEncode( "Request a new client-credentials token.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Reuse the matching token from the credential store.") & "</pre>"
%>
</body>
</html>