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

DataFlex 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
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

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
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
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

 

 

 

(DataFlex) 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 ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoJsonToken
    Boolean iSuccess
    Handle hoHttp
    Variant vReq
    Handle hoReq
    Handle hoFac
    Variant hoJpgBytes
    Variant vResp
    Handle hoResp
    Handle hoJsonResponse
    String sTemp1
    Integer iTemp1
    Integer iTemp2
    Boolean bTemp1

    // 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..
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken
    If (Not(IsComObjectCreated(hoJsonToken))) Begin
        Send CreateComObject of hoJsonToken
    End
    Get ComLoadFile Of hoJsonToken "qa_data/tokens/twitter.json" To iSuccess

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // Provide the OAuth 1.0a credentials:
    Set ComOAuth1 Of hoHttp To True
    Set ComOAuthConsumerKey Of hoHttp To "TWITTER_CONSUMER_KEY"
    Set ComOAuthConsumerSecret Of hoHttp To "TWITTER_CONSUMER_SECRET"
    Get ComStringOf Of hoJsonToken "oauth_token" To sTemp1
    Set ComOAuthToken Of hoHttp To sTemp1
    Get ComStringOf Of hoJsonToken "oauth_token_secret" To sTemp1
    Set ComOAuthTokenSecret Of hoHttp To sTemp1

    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End
    Set ComHttpVerb Of hoReq To "POST"
    Set ComContentType Of hoReq To "multipart/form-data"
    Set ComPath Of hoReq To "/1.1/media/upload.json"

    Send ComAddHeader To hoReq "Expect" "100-continue"

    // Add a JPEG image file to the upload.
    Get Create (RefClass(cComCkFileAccess)) To hoFac
    If (Not(IsComObjectCreated(hoFac))) Begin
        Send CreateComObject of hoFac
    End

    Get ComReadEntireFile Of hoFac "qa_data/jpg/starfish.jpg" To hoJpgBytes
    Get ComAddBytesForUpload Of hoReq "media" "starfish.jpg" vJpgBytes To iSuccess

    Get pvComObject of hoReq to vReq
    Get ComSynchronousRequest Of hoHttp "upload.twitter.com" 443 True vReq To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse
    If (Not(IsComObjectCreated(hoJsonResponse))) Begin
        Send CreateComObject of hoJsonResponse
    End
    Set ComEmitCompact Of hoJsonResponse To False
    Get ComBodyStr Of hoResp To sTemp1
    Get ComLoad Of hoJsonResponse sTemp1 To iSuccess

    Get ComStatusCode Of hoResp To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComEmit Of hoJsonResponse To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Send Destroy of hoResp

    // Show the successful response:
    Get ComEmit Of hoJsonResponse To sTemp1
    Showln sTemp1
    Showln "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:
    Get ComStringOf Of hoJsonResponse "media_id_string" To sTemp1
    Showln "media_id_string = " sTemp1
    Get ComIntOf Of hoJsonResponse "size" To iTemp1
    Showln "size = " iTemp1
    Get ComStringOf Of hoJsonResponse "image.image_type" To sTemp1
    Showln "image_type = " sTemp1
    Get ComIntOf Of hoJsonResponse "image.w" To iTemp1
    Get ComIntOf Of hoJsonResponse "image.h" To iTemp2
    Showln "height/width = " iTemp1 "," iTemp2


End_Procedure

 

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