Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Tcl Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Bitfinex v2 REST
Bluzone
BrickLink
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun
Mastercard

MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
Trello
Twilio
Twitter API v2
Twitter v1
UniPin
VoiceBase
Vonage
Walmart
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yousign
ZATCA
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(Tcl) ETrade OAuth1 Authorization (3-legged) Step 2

Demonstrates the final step in 3-legged OAuth1 authorization for the ETrade REST API. Example uses the OAuth1 verifier code that was copy-and-pasted from the browser in the 1st step. The end result of this final OAuth1 step is an access token that can be used to make ETrade REST API calls.

See https://apisb.etrade.com/docs/api/authorization/get_access_token.html

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

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

set consumerKey "ETRADE_CONSUMER_KEY"
set consumerSecret "ETRADE_CONSUMER_SECRET"

set requestTokenUrl "https://apisb.etrade.com/oauth/request_token"
set authorizeUrl "https://us.etrade.com/e/t/etws/authorize"
set accessTokenUrl "https://apisb.etrade.com/oauth/access_token"

set http [new_CkHttp]

set success 1

CkHttp_put_OAuth1 $http 1
CkHttp_put_OAuthConsumerKey $http $consumerKey
CkHttp_put_OAuthConsumerSecret $http $consumerSecret
CkHttp_put_OAuthCallback $http "oob"

set jsonRequestToken [new_CkJsonObject]

set success [CkJsonObject_LoadFile $jsonRequestToken "qa_data/tokens/etrade_request_token.json"]
set requestToken [CkJsonObject_stringOf $jsonRequestToken "oauth_token"]
set requestTokenSecret [CkJsonObject_stringOf $jsonRequestToken "oauth_token_secret"]

# ------------------------------------------------------------------------------
# Exchange the OAuth Request Token for an OAuth Access Token.

CkHttp_put_OAuthToken $http $requestToken
CkHttp_put_OAuthTokenSecret $http $requestTokenSecret

# This is the verifier that was interactively copy-and-pasted from the browser back to our app.
CkHttp_put_OAuthVerifier $http "NJ07S"

# resp is a CkHttpResponse
set resp [CkHttp_QuickGetObj $http $accessTokenUrl]
if {[CkHttp_get_LastMethodSuccess $http] != 1} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $jsonRequestToken
    exit
}

# Make sure a successful response was received.
if {[CkHttpResponse_get_StatusCode $resp] != 200} then {
    puts [CkHttpResponse_statusLine $resp]
    puts [CkHttpResponse_header $resp]
    puts [CkHttpResponse_bodyStr $resp]
    delete_CkHttp $http
    delete_CkJsonObject $jsonRequestToken
    exit
}

# If successful, the resp.BodyStr contains something like this:
# oauth_token=85123455-fF41296Bi3daM8eCo9Y5vZabcdxXpRv864plYPOjr&oauth_token_secret=afiYJOgabcdSfGae7BDvJVVTwys8fUGpra5guZxbmFBZo
puts [CkHttpResponse_bodyStr $resp]

set hashTab [new_CkHashtable]

CkHashtable_AddQueryParams $hashTab [CkHttpResponse_bodyStr $resp]

set accessToken [CkHashtable_lookupStr $hashTab "oauth_token"]
set accessTokenSecret [CkHashtable_lookupStr $hashTab "oauth_token_secret"]

delete_CkHttpResponse $resp

# The access token + secret is what should be saved and used for
# subsequent REST API calls.
puts "Access Token = $accessToken"
puts "Access Token Secret = $accessTokenSecret"

# Save this access token for future calls.
# Just in case we need user_id and screen_name, save those also..
set json [new_CkJsonObject]

CkJsonObject_AppendString $json "oauth_token" $accessToken
CkJsonObject_AppendString $json "oauth_token_secret" $accessTokenSecret

set fac [new_CkFileAccess]

CkFileAccess_WriteEntireTextFile $fac "qa_data/tokens/etrade.json" [CkJsonObject_emit $json] "utf-8" 0

puts "Success."

delete_CkHttp $http
delete_CkJsonObject $jsonRequestToken
delete_CkHashtable $hashTab
delete_CkJsonObject $json
delete_CkFileAccess $fac

 

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