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 SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
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
OpenAI ChatGPT
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
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(Tcl) Upload Media to Twitter

Demonstrates uploading image or video files to Twitter. After uploading, the media_id can be used to attach the uploaded media to a tweet.

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

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

# Assume we've previously obtained an access token and saved it to a JSON file..
set jsonToken [new_CkJsonObject]

set success [CkJsonObject_LoadFile $jsonToken "qa_data/tokens/twitter.json"]

set http [new_CkHttp]

# Provide the OAuth 1.0a credentials:
CkHttp_put_OAuth1 $http 1
CkHttp_put_OAuthConsumerKey $http "TWITTER_CONSUMER_KEY"
CkHttp_put_OAuthConsumerSecret $http "TWITTER_CONSUMER_SECRET"
CkHttp_put_OAuthToken $http [CkJsonObject_stringOf $jsonToken "oauth_token"]
CkHttp_put_OAuthTokenSecret $http [CkJsonObject_stringOf $jsonToken "oauth_token_secret"]

set req [new_CkHttpRequest]

CkHttpRequest_put_HttpVerb $req "POST"
CkHttpRequest_put_ContentType $req "multipart/form-data"
CkHttpRequest_put_Path $req "/1.1/media/upload.json"

CkHttpRequest_AddHeader $req "Expect" "100-continue"

# Add a JPEG image file to the upload.
set fac [new_CkFileAccess]

set jpgBytes [new_CkByteData]

set success [CkFileAccess_ReadEntireFile $fac "qa_data/jpg/starfish.jpg" $jpgBytes]
CkHttpRequest_AddBytesForUpload $req "media" "starfish.jpg" $jpgBytes

# resp is a CkHttpResponse
set resp [CkHttp_SynchronousRequest $http "upload.twitter.com" 443 1 $req]
if {[CkHttp_get_LastMethodSuccess $http] != 1} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkJsonObject $jsonToken
    delete_CkHttp $http
    delete_CkHttpRequest $req
    delete_CkFileAccess $fac
    delete_CkByteData $jpgBytes
    exit
}

set jsonResponse [new_CkJsonObject]

CkJsonObject_put_EmitCompact $jsonResponse 0
CkJsonObject_Load $jsonResponse [CkHttpResponse_bodyStr $resp]

if {[CkHttpResponse_get_StatusCode $resp] != 200} then {
    puts [CkJsonObject_emit $jsonResponse]
    delete_CkJsonObject $jsonToken
    delete_CkHttp $http
    delete_CkHttpRequest $req
    delete_CkFileAccess $fac
    delete_CkByteData $jpgBytes
    delete_CkJsonObject $jsonResponse
    exit
}

delete_CkHttpResponse $resp

# Show the successful response:
puts [CkJsonObject_emit $jsonResponse]
puts "Success."

# A successful JSON response looks like this:

# 	{
# 	  "media_id": 793137045996646400,
# 	  "media_id_string": "793137045996646400",
# 	  "size": 6229,
# 	  "expires_after_secs": 86400,
# 	  "image": {
# 	    "image_type": "image\/jpeg",
# 	    "w": 120,
# 	    "h": 120
# 	  }
# 	}
# 

# Get the information from the JSON:
puts "media_id_string = [CkJsonObject_stringOf $jsonResponse media_id_string]"
puts "size = [CkJsonObject_IntOf $jsonResponse size]"
puts "image_type = [CkJsonObject_stringOf $jsonResponse image.image_type]"
puts "height/width = [CkJsonObject_IntOf $jsonResponse image.w],[CkJsonObject_IntOf $jsonResponse image.h]"

delete_CkJsonObject $jsonToken
delete_CkHttp $http
delete_CkHttpRequest $req
delete_CkFileAccess $fac
delete_CkByteData $jpgBytes
delete_CkJsonObject $jsonResponse

 

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