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 Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
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)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(DataFlex) Dropbox: Access Your Own Account

To programmatically interact with your own Dropbox account, such as for uploading, downloading, listing files, etc., go to the Dropbox app console and create an application. Then generate an access token in the online app console as shown in the screenshot below. The access token does not expire, and can be used to access your own account from your own non-web application.

The example code, located below the screenshot, shows how to list the files in the root folder.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iBTls
    Integer iPort
    Boolean iBAutoReconnect
    Boolean iSuccess
    Handle hoJson
    String sResponseStr
    Handle hoJsonResponse
    Integer iNumEntries
    Integer i
    Handle hoCkdt
    Boolean iBLocalDateTime
    Variant vDt
    Handle hoDt
    String sTemp1
    Integer iTemp1
    Integer iTemp2
    Integer iTemp3
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    // Connect to the www.dropbox.com endpoint.
    Move True To iBTls
    Move 443 To iPort
    Move True To iBAutoReconnect
    Get ComConnect Of hoRest "api.dropboxapi.com" iPort iBTls iBAutoReconnect To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComAddHeader Of hoRest "Content-Type" "application/json" To iSuccess
    Get ComAddHeader Of hoRest "Authorization" "Bearer DROPBOX-ACCESS-TOKEN" To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    // The root folder should be an empty string, not "/"
    Get ComAppendString Of hoJson "path" "" To iSuccess
    Get ComAppendBool Of hoJson "recursive" False To iSuccess
    Get ComAppendBool Of hoJson "include_media_info" False To iSuccess
    Get ComAppendBool Of hoJson "include_deleted" False To iSuccess
    Get ComAppendBool Of hoJson "include_has_explicit_shared_members" False To iSuccess

    Get ComEmit Of hoJson To sTemp1
    Get ComFullRequestString Of hoRest "POST" "/2/files/list_folder" sTemp1 To sResponseStr
    Get ComLastMethodSuccess Of hoRest To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Success is indicated by a 200 response status code.
    Get ComResponseStatusCode Of hoRest To iTemp1
    If (iTemp1 <> 200) Begin
        // Examine the request/response to see what happened.
        Get ComResponseStatusCode Of hoRest To iTemp1
        Showln "response status code = " iTemp1
        Get ComResponseStatusText Of hoRest To sTemp1
        Showln "response status text = " sTemp1
        Get ComResponseHeader Of hoRest To sTemp1
        Showln "response header: " sTemp1
        Showln "response body (if any): " sResponseStr
        Showln "---"
        Get ComLastRequestStartLine Of hoRest To sTemp1
        Showln "LastRequestStartLine: " sTemp1
        Get ComLastRequestHeader Of hoRest To sTemp1
        Showln "LastRequestHeader: " sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse
    If (Not(IsComObjectCreated(hoJsonResponse))) Begin
        Send CreateComObject of hoJsonResponse
    End
    Get ComLoad Of hoJsonResponse sResponseStr To iSuccess

    Set ComEmitCompact Of hoJsonResponse To False
    Get ComEmit Of hoJsonResponse To sTemp1
    Showln sTemp1

    // A sample JSON response is shown at the end of this example.
    // The following code iterates over the entries.
    Get ComSizeOfArray Of hoJsonResponse "entries" To iNumEntries
    Move 0 To i
    While (i < iNumEntries)
        Set ComI Of hoJsonResponse To i
        Showln "----"
        Get ComStringOf Of hoJsonResponse "entries[i].name" To sTemp1
        Showln "name: " sTemp1
        Get ComStringOf Of hoJsonResponse "entries[i].path_lower" To sTemp1
        Showln "path_lower: " sTemp1
        Get ComStringOf Of hoJsonResponse "entries[i].path_display" To sTemp1
        Showln "path_display: " sTemp1
        Get ComHasMember Of hoJsonResponse "entries[i].sharing_info" To bTemp1
        If (bTemp1 = True) Begin
            Showln "has sharing_info..."
            Get ComStringOf Of hoJsonResponse "entries[i].sharing_info.read_only" To sTemp1
            Showln "read_only: " sTemp1
            Get ComStringOf Of hoJsonResponse "entries[i].sharing_info.shared_folder_id" To sTemp1
            Showln "shared_folder_id: " sTemp1
        End

        Get ComHasMember Of hoJsonResponse "entries[i].client_modified" To bTemp1
        If (bTemp1 = True) Begin
            // Demonstrate how to parse a date/time:
            Get Create (RefClass(cComCkDateTime)) To hoCkdt
            If (Not(IsComObjectCreated(hoCkdt))) Begin
                Send CreateComObject of hoCkdt
            End
            Get ComStringOf Of hoJsonResponse "entries[i].client_modified" To sTemp1
            Get ComSetFromTimestamp Of hoCkdt sTemp1 To iSuccess
            // The date/time can now be converted to many other formats, or the individual parts
            // can be accessed.
            Move True To iBLocalDateTime
            Get ComGetDtObj Of hoCkdt iBLocalDateTime To vDt
            If (IsComObject(vDt)) Begin
                Get Create (RefClass(cComChilkatDtObj)) To hoDt
                Set pvComObject Of hoDt To vDt
            End
            Get ComYear Of hoDt To iTemp1
            Get ComMonth Of hoDt To iTemp2
            Get ComDay Of hoDt To iTemp3
            Showln iTemp1 "-" iTemp2 "-" iTemp3
            Send Destroy of hoDt
        End

        Move (i + 1) To i
    Loop

    Showln "Success."

    // {
    //   "entries": [
    //     {
    //       ".tag": "folder",
    //       "name": "chilkat Team Folder",
    //       "path_lower": "/chilkat team folder",
    //       "path_display": "/chilkat Team Folder",
    //       "id": "id:2VqX9RLr-JAAAAAAAAAAAQ",
    //       "shared_folder_id": "1210954290",
    //       "sharing_info": {
    //         "read_only": false,
    //         "shared_folder_id": "1210954290"
    //       }
    //     },
    //     {
    //       ".tag": "file",
    //       "name": "Get Started with Dropbox.pdf",
    //       "path_lower": "/get started with dropbox.pdf",
    //       "path_display": "/Get Started with Dropbox.pdf",
    //       "id": "id:oxE2oMDqH4AAAAAAAAAAAQ",
    //       "client_modified": "2016-05-07T11:47:47Z",
    //       "server_modified": "2016-05-07T11:47:47Z",
    //       "rev": "1483db13f",
    //       "size": 692088
    //     }
    //   ],
    //   "cursor": "AAEnZXciJyS4gzC_tlX6K2na4c8o7_09-dxmXKHpkPPyf3Kl0H4N-VYnz424nCrFOJuhMiM5_RgNAersumx9qe7NgCSdlppr80iFk0gf6vPlecM6SBtLcs6OYXL8ILWiZ62pfnOvgC3WKGlG6dqZ-VXH",
    //   "has_more": false
    // }
    // 


End_Procedure

 

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