Chilkat Examples

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

DataFlex Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
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
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
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun

MedTunnel
MercadoLibre
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
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
UniPin
VoiceBase
Vonage
Walmart
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yousign
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-9.5.0-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-2022 Chilkat Software, Inc. All Rights Reserved.