Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Java Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)

Java KeyStore (JKS)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(Java) Check PayPal Access Token Expiration

Checks to see if the PayPal access token expired.

Chilkat Java Downloads

Java Libs for Windows, Linux, Alpine Linux,
MAC OS X, Solaris, FreeBSD, OpenBSD,
Raspberry Pi and other single board computers

Java Libs for Android

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    //  Note: Requires Chilkat v9.5.0.64 or greater.

    //  This requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    //  In the example linked here: PayPal OAuth2 Token,
    //  we fetched a PayPal access token and saved it to a JSON file.
    //  We also recorded the current date/time.
    //  Load this JSON file and compare the current date/time with the fetch date/time
    //  and the "expires_in" value to see if the token is expired.

    CkJsonObject json = new CkJsonObject();
    boolean success = json.LoadFile("qa_data/tokens/paypal.json");
    if (success != true) {
        System.out.println("Failed to load access key json file.");
        return;
        }

    //  Get the current date/time.
    CkDateTime dateTime = new CkDateTime();
    boolean bLocalTime = false;
    int dtNow = dateTime.GetAsUnixTime(bLocalTime);

    //  Get the access token create date/time
    int dtCreate = json.IntOf("tokenCreateTimeUtc");

    //  Find out how many seconds have elapsed.
    int numSeconds = dtNow - dtCreate;

    //  Get the expires_in value from the JSON.
    int expires_in = json.IntOf("expires_in");

    System.out.println("token age (in seconds) = " + numSeconds);
    System.out.println("expires_in = " + expires_in);

    //  If the token expired, or if it will expire in 5 minutes or less,
    //  get another token.
    if (numSeconds < (expires_in - 300)) {
        System.out.println("The token is not yet expired.  No need to fetch another.");
        return;
        }

    System.out.println("Time to fetch a new access token...");

    //  Get another token..
    //  See the example at Get PayPal OAuth2 Token
    //  to get another token..
  }
}

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.