Hi. i got this error of
"Error: StatusCode=400, version 0 of the API is not supported"
This is my code
and i still stuck with the error.. i really need some help
"Error: StatusCode=400, version 0 of the API is not supported"
This is my code
B4X:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: Dropbox Example
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
'Activity module
Sub Process_Globals
Dim developerKey, developerSecret, token, tokenSecret As String
developerKey = "96kcdxy9w69cyvv" '<--- must be set!
developerSecret = "i0d433b0yskmiss"
Dim infoLink, metadataLink, downloadFileLink, uploadLink As String
infoLink = "https://api.dropbox.com/1/account/info"
metadataLink = "https://api.dropbox.com/1/metadata/dropbox"
downloadFileLink = "https://api-content.dropbox.com/1/files/dropbox"
uploadLink = "https://api-content.dropbox.com/1/files/dropbox"
Dim currentPath As String
currentPath = "/"
Type FileEntry(FilePath As String, IsDir As Boolean)
Dim downloadedFile As FileEntry
Dim targetPath As String
Dim FilesCache As Map
End Sub
Sub Globals
Dim ListView1 As ListView
Dim lblPath As Label
Dim FileDialog As FileDialog
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
End If
FilesCache.Initialize
FileDialog.FilePath = File.DirRootExternal
Activity.LoadLayout("Main")
'Make the listview take the whole available space.
ListView1.Width = 100%x
ListView1.Height = 100%y - ListView1.Top
lblPath.Width = 100%x
End Sub
Sub Activity_Resume
If HttpUtils.Working = True Then ProgressDialogShow2("Waiting for operation to complete...", False)
If HttpUtils.Complete = True Then JobDone(HttpUtils.Job)
If token = "" Then LoadTokenKey
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub LoadTokenKey
'Once we get a token from Dropbox it should be saved for future requests.
'So here we check if we already have such a token.
'If not then we show the user credentials form.
If File.Exists(File.DirInternal, "token.txt") Then
Dim l As List
l = File.ReadList(File.DirInternal, "token.txt")
tokenKey = l.Get(0)
tokenSecret = l.Get(1)
If HttpUtilsService.OAuth.IsInitialized = False Then
HttpUtilsService.OAuth.Initialize(developerKey, developerSecret)
End If
HttpUtilsService.OAuth.SetTokenWithSecret(tokenKey, tokenSecret)
HttpUtils.CallbackActivity = "Main"
HttpUtils.CallbackJobDoneSub = "JobDone"
ChangePath(currentPath, True) 'Load the current path data
Else
StartActivity(UserForm)
End If
End Sub
Sub ChangePath(p As String, AllowFromCache As Boolean)
targetPath = p 'Store the target path so we can later use it (if the change was successful)
If AllowFromCache AND FilesCache.ContainsKey(p) Then
'load the data from the cache
HandleChangePathResult(FilesCache.Get(p))
Else
ProgressDialogShow2("Connecting to Dropbox server...", False)
HttpUtils.Download("changepath", HttpUtils.EncodeUrl(metadataLink & p & "?"))
End If
End Sub
Sub HandleChangePathResult(Response As Map)
ListView1.Clear
Dim files As List
files = Response.Get("contents")
currentPath = targetPath
FilesCache.Put(currentPath, Response)
lblPath.Text = "Path: " & currentPath
Dim m As Map
'First we add the folders and theh the files
If currentPath <> "/" Then
'add the Up folder if it is not the root folder
Dim fe As FileEntry
fe.IsDir = True
fe.FilePath = currentPath.SubString2(0, currentPath.LastIndexOf2("/", currentPath.Length - 2) + 1)
ListView1.AddTwoLines2("Up", "Folder", fe)
End If
For i = 0 To files.Size - 1
m = files.Get(i)
If m.Get("is_dir") = True Then
Dim fe As FileEntry
fe.IsDir = True
fe.FilePath = m.Get("path")
fe.FilePath = fe.FilePath.SubString(currentPath.Length)
ListView1.AddTwoLines2(fe.FilePath, "Folder", fe) 'FileEntry is set as the return value
End If
Next
For i = 0 To files.Size - 1
m = files.Get(i)
If m.Get("is_dir") = False Then
Dim fe As FileEntry
fe.IsDir = False
fe.FilePath = m.Get("path")
fe.FilePath = fe.FilePath.SubString(currentPath.Length)
ListView1.AddTwoLines2(fe.FilePath, m.Get("size"), fe)
End If
Next
End Sub
Sub DownloadFile(FE As FileEntry)
downloadedFile = FE
ProgressDialogShow2("Downloading " & FE.FilePath & "...", False)
HttpUtils.Download("download", HttpUtils.EncodeUrl(downloadFileLink & currentPath & FE.FilePath & "?"))
End Sub
Sub HandleDownloadFileResult(In As InputStream)
Dim out As OutputStream
out = File.OpenOutput(File.DirRootExternal, downloadedFile.FilePath, False)
File.Copy2(In, out)
out.Close
ToastMessageShow(downloadedFile.FilePath & " downloaded successfully.", True)
End Sub
Sub UploadFile
If FileDialog.Show("Choose file to upload", "Ok", "Cancel", "", Null) = DialogResponse.POSITIVE Then
ProgressDialogShow2("Uploading " & FileDialog.ChosenName _
& " (" & (Ceil(File.Size(FileDialog.FilePath, FileDialog.ChosenName) / 1000)) & " Kb)", False)
HttpUtils.PostFile("upload", HttpUtils.EncodeUrl(uploadLink & currentPath), _
FileDialog.FilePath, FileDialog.ChosenName)
End If
End Sub
Sub HandleUploadFileResult
ToastMessageShow("File uploaded successfully.", True)
ChangePath(currentPath, False) 'refresh to show the new file
End Sub
Sub JobDone(Job As String)
ProgressDialogHide
If HttpUtils.IsSuccess(HttpUtils.Tasks.Get(0)) Then
Select Job
Case "download"
HandleDownloadFileResult(HttpUtils.GetInputStream(HttpUtils.Tasks.Get(0)))
Case "upload"
HandleUploadFileResult
Case "changepath"
Dim j As JSONParser
j.Initialize(HttpUtils.GetString(HttpUtils.Tasks.Get(0)))
Dim Response As Map
Response = j.NextObject
HandleChangePathResult(Response)
End Select
End If
HttpUtils.Complete = False
End Sub
Sub ListView1_ItemClick (Position As Int, Value As Object)
Dim fe As FileEntry
fe = Value
If fe.IsDir Then
'Change path
Dim p As String
If fe.FilePath.StartsWith("/") = False Then
p = currentPath & fe.FilePath & "/"
Else
'full path is given
p = fe.FilePath
End If
ChangePath(p, True)
Else
ToastMessageShow("Long click to download file.", True)
End If
End Sub
Sub ListView1_ItemLongClick (Position As Int, Value As Object)
Dim fe As FileEntry
fe = Value
If fe.IsDir = False Then
DownloadFile(fe)
Else
ListView1_ItemClick(Position, Value) 'handle the long click as we handle regular clicks.
End If
End Sub
Sub btnRefresh_Click
ChangePath(currentPath, False)
End Sub
Sub btnUpload_Click
UploadFile
End Sub
and i still stuck with the error.. i really need some help