Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Dropbox: Access Your Own AccountTo 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.
Use ChilkatAx-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.