Sample code for 30+ languages & platforms
Visual FoxPro

Dropbox: Get Space Usage

See more Dropbox Examples

Demonstrates how to get the Dropbox space usage information for the current user's account.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loRest
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL lcResponseStr
LOCAL loJsonResponse

lnSuccess = 0

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

loRest = CreateObject('Chilkat.Rest')

* Connect to the www.dropbox.com endpoint.
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("api.dropboxapi.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loRest.AddHeader("Authorization","Bearer DROPBOX-ACCESS-TOKEN")

lcResponseStr = loRest.FullRequestNoBody("POST","/2/users/get_space_usage")
IF (loRest.LastMethodSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

* Success is indicated by a 200 response status code.
IF (loRest.ResponseStatusCode <> 200) THEN
    * Examine the request/response to see what happened.
    ? "response status code = " + STR(loRest.ResponseStatusCode)
    ? "response status text = " + loRest.ResponseStatusText
    ? "response header: " + loRest.ResponseHeader
    ? "response body (if any): " + lcResponseStr
    ? "---"
    ? "LastRequestStartLine: " + loRest.LastRequestStartLine
    ? "LastRequestHeader: " + loRest.LastRequestHeader
    RELEASE loRest
    CANCEL
ENDIF

loJsonResponse = CreateObject('Chilkat.JsonObject')
loJsonResponse.Load(lcResponseStr)

loJsonResponse.EmitCompact = 0
? loJsonResponse.Emit()

* {
*   "used": 3032115,
*   "allocation": {
*     ".tag": "individual",
*     "allocated": 2147483648
*   }
* }
* 

RELEASE loRest
RELEASE loJsonResponse