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

Tcl 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

 

 

 

(Tcl) Refresh QuickBooks OAuth2 Access Token

Demonstrates how to refresh a QuickBooks OAuth2 access token.

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

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

#  See Get QuickBooks OAuth2 Access Token
#  for sample code showing how to obtain a QuickBooks access token for desktop apps.

#  This example assumes we previously obtained an OAuth2 access token for QuickBooks.

set jsonToken [new_CkJsonObject]

set success [CkJsonObject_LoadFile $jsonToken "qa_data/tokens/qb-access-token.json"]
if {[expr $success != 1]} then {
    puts "Failed to load qb-access-token.json"
    delete_CkJsonObject $jsonToken
    exit
}

#  The access token JSON looks something like this:

#  {
#    "expires_in": 3600,
#    "x_refresh_token_expires_in": 8726400,
#    "refresh_token": "L011546037639r ... 3vR2DrbOmg0Sdagw",
#    "access_token": "eyJlbmMiOiJBMTI4Q0 ... oETJEMbeggg",
#    "token_type": "bearer"
#  }

set oauth2 [new_CkOAuth2]

CkOAuth2_put_TokenEndpoint $oauth2 "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer"

#  Replace these with actual values.
CkOAuth2_put_ClientId $oauth2 "QUICKBOOKS-CLIENT-ID"
CkOAuth2_put_ClientSecret $oauth2 "QUICKBOOKS-CLIENT-SECRET"

#  Get the "refresh_token"
CkOAuth2_put_RefreshToken $oauth2 [CkJsonObject_stringOf $jsonToken "refresh_token"]

#  Send the HTTP POST to refresh the access token..
set success [CkOAuth2_RefreshAccessToken $oauth2]
if {[expr $success != 1]} then {
    puts [CkOAuth2_lastErrorText $oauth2]
    delete_CkJsonObject $jsonToken
    delete_CkOAuth2 $oauth2
    exit
}

#  Save the new JSON access token response to a file.
#  The access + refresh tokens contained in this JSON will be needed for the next refresh.
set sbJson [new_CkStringBuilder]

CkJsonObject_put_EmitCompact $jsonToken 0
CkJsonObject_EmitSb $jsonToken $sbJson
CkStringBuilder_WriteFile $sbJson "qa_data/tokens/qb-access-token.json" "utf-8" 0

puts "OAuth2 token refreshed!"
puts "New Access Token = [CkOAuth2_accessToken $oauth2]"

delete_CkJsonObject $jsonToken
delete_CkOAuth2 $oauth2
delete_CkStringBuilder $sbJson

 

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