Sample code for 30+ languages & platforms
B4X

Dropbox: Get Space Usage

See more Dropbox Examples

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

Chilkat B4X Downloads

B4X
Dim success As Boolean = False

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

Dim rest As ChilkatRest
rest.Initialize("rest")

'  Connect to the www.dropbox.com endpoint.
Dim bTls As Boolean = True
Dim port As Int = 443
Dim bAutoReconnect As Boolean = True
success = rest.Connect("api.dropboxapi.com", port, bTls, bAutoReconnect)
If success <> True Then
    Log(rest.LastErrorText)
    Return
End If


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

Dim responseStr As String = rest.FullRequestNoBody("POST", "/2/users/get_space_usage")
If rest.LastMethodSuccess <> True Then
    Log(rest.LastErrorText)
    Return
End If


'  Success is indicated by a 200 response status code.
If rest.ResponseStatusCode <> 200 Then
    '  Examine the request/response to see what happened.
    Log("response status code = " & rest.ResponseStatusCode)
    Log("response status text = " & rest.ResponseStatusText)
    Log("response header: " & rest.ResponseHeader)
    Log("response body (if any): " & responseStr)
    Log("---")
    Log("LastRequestStartLine: " & rest.LastRequestStartLine)
    Log("LastRequestHeader: " & rest.LastRequestHeader)
    Return
End If


Dim jsonResponse As ChilkatJsonObject
jsonResponse.Initialize
jsonResponse.Load(responseStr)

jsonResponse.EmitCompact = False
Log(jsonResponse.Emit)

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