Xbase++
Xbase++
Dropbox: Get Space Usage
See more Dropbox Examples
Demonstrates how to get the Dropbox space usage information for the current user's account.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nPort
LOCAL nBAutoReconnect
LOCAL cResponseStr
LOCAL oJsonResponse
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oRest := CreateObject("Chilkat.Rest")
// Connect to the www.dropbox.com endpoint.
nBTls := 1
nPort := 443
nBAutoReconnect := 1
nSuccess := oRest:Connect("api.dropboxapi.com", nPort, nBTls, nBAutoReconnect)
IF (nSuccess != 1)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
oRest:AddHeader("Authorization", "Bearer DROPBOX-ACCESS-TOKEN")
cResponseStr := oRest:FullRequestNoBody("POST", "/2/users/get_space_usage")
IF (oRest:LastMethodSuccess != 1)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
// Success is indicated by a 200 response status code.
IF (oRest:ResponseStatusCode != 200)
// Examine the request/response to see what happened.
? "response status code = " + Str(oRest:ResponseStatusCode)
? "response status text = " + oRest:ResponseStatusText
? "response header: " + oRest:ResponseHeader
? "response body (if any): " + cResponseStr
? "---"
? "LastRequestStartLine: " + oRest:LastRequestStartLine
? "LastRequestHeader: " + oRest:LastRequestHeader
oRest:destroy()
RETURN
ENDIF
oJsonResponse := CreateObject("Chilkat.JsonObject")
oJsonResponse:Load(cResponseStr)
oJsonResponse:EmitCompact := 0
? oJsonResponse:Emit()
// {
// "used": 3032115,
// "allocation": {
// ".tag": "individual",
// "allocated": 2147483648
// }
// }
//
oRest:destroy()
oJsonResponse:destroy()