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
(PureBasic) 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.
IncludeFile "CkDtObj.pb" IncludeFile "CkRest.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkDateTime.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. rest.i = CkRest::ckCreate() If rest.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Connect to the www.dropbox.com endpoint. bTls.i = 1 port.i = 443 bAutoReconnect.i = 1 success.i = CkRest::ckConnect(rest,"api.dropboxapi.com",port,bTls,bAutoReconnect) If success <> 1 Debug CkRest::ckLastErrorText(rest) CkRest::ckDispose(rest) ProcedureReturn EndIf CkRest::ckAddHeader(rest,"Content-Type","application/json") CkRest::ckAddHeader(rest,"Authorization","Bearer DROPBOX-ACCESS-TOKEN") json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; The root folder should be an empty string, not "/" CkJsonObject::ckAppendString(json,"path","") CkJsonObject::ckAppendBool(json,"recursive",0) CkJsonObject::ckAppendBool(json,"include_media_info",0) CkJsonObject::ckAppendBool(json,"include_deleted",0) CkJsonObject::ckAppendBool(json,"include_has_explicit_shared_members",0) responseStr.s = CkRest::ckFullRequestString(rest,"POST","/2/files/list_folder",CkJsonObject::ckEmit(json)) If CkRest::ckLastMethodSuccess(rest) <> 1 Debug CkRest::ckLastErrorText(rest) CkRest::ckDispose(rest) CkJsonObject::ckDispose(json) ProcedureReturn EndIf ; Success is indicated by a 200 response status code. If CkRest::ckResponseStatusCode(rest) <> 200 ; Examine the request/response to see what happened. Debug "response status code = " + Str(CkRest::ckResponseStatusCode(rest)) Debug "response status text = " + CkRest::ckResponseStatusText(rest) Debug "response header: " + CkRest::ckResponseHeader(rest) Debug "response body (if any): " + responseStr Debug "---" Debug "LastRequestStartLine: " + CkRest::ckLastRequestStartLine(rest) Debug "LastRequestHeader: " + CkRest::ckLastRequestHeader(rest) CkRest::ckDispose(rest) CkJsonObject::ckDispose(json) ProcedureReturn EndIf jsonResponse.i = CkJsonObject::ckCreate() If jsonResponse.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoad(jsonResponse,responseStr) CkJsonObject::setCkEmitCompact(jsonResponse, 0) Debug CkJsonObject::ckEmit(jsonResponse) ; A sample JSON response is shown at the end of this example. ; The following code iterates over the entries. numEntries.i = CkJsonObject::ckSizeOfArray(jsonResponse,"entries") i.i = 0 While i < numEntries CkJsonObject::setCkI(jsonResponse, i) Debug "----" Debug "name: " + CkJsonObject::ckStringOf(jsonResponse,"entries[i].name") Debug "path_lower: " + CkJsonObject::ckStringOf(jsonResponse,"entries[i].path_lower") Debug "path_display: " + CkJsonObject::ckStringOf(jsonResponse,"entries[i].path_display") If CkJsonObject::ckHasMember(jsonResponse,"entries[i].sharing_info") = 1 Debug "has sharing_info..." Debug "read_only: " + CkJsonObject::ckStringOf(jsonResponse,"entries[i].sharing_info.read_only") Debug "shared_folder_id: " + CkJsonObject::ckStringOf(jsonResponse,"entries[i].sharing_info.shared_folder_id") EndIf If CkJsonObject::ckHasMember(jsonResponse,"entries[i].client_modified") = 1 ; Demonstrate how to parse a date/time: ckdt.i = CkDateTime::ckCreate() If ckdt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkDateTime::ckSetFromTimestamp(ckdt,CkJsonObject::ckStringOf(jsonResponse,"entries[i].client_modified")) ; The date/time can now be converted to many other formats, or the individual parts ; can be accessed. bLocalDateTime.i = 1 dt.i = CkDateTime::ckGetDtObj(ckdt,bLocalDateTime) Debug Str(CkDtObj::ckYear(dt)) + "-" + Str(CkDtObj::ckMonth(dt)) + "-" + Str(CkDtObj::ckDay(dt)) CkDtObj::ckDispose(dt) EndIf i = i + 1 Wend Debug "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 ; } ; CkRest::ckDispose(rest) CkJsonObject::ckDispose(json) CkJsonObject::ckDispose(jsonResponse) CkDateTime::ckDispose(ckdt) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.