Android Question Error: StatusCode=400, version 0 of the API is not supported

Lyndon Bermoy

Active Member
Licensed User
Hi. i got this error of
"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
 

udg

Expert
Licensed User
..and if
B4X:
developerKey = "96kcdxy9w69cyvv"'<--- must be set! 
developerSecret = "i0d433b0yskmiss"
are your real keys.. it's now time to change them! ;)
 

Lyndon Bermoy

Active Member
Licensed User
this Forum has a search box, you should use it.
Thanks @Cableguy ! I already fixed to have download files from the dropbox but when it comes to uploading files I've got an error

Here's the log:

LogCat connected to: ZTTCRWCMGIAE5SJ7

com.dropbox.sync.android.DbxException$Disallowed: jlong dropboxsync::Java_com_dropbox_sync_android_NativeFileSystem_nativeOpenFile(JNIEnv*, jobject, jlong, jlong, jint) - App is not allowed access: app is not allowed to create file p(/t4/h4/g4.sqlite)


at com.dropbox.sync.android.DbxError.exceptionFrom(DbxError.java:276)
at com.dropbox.sync.android.NativeLib.exceptionFrom(NativeLib.java:254)
at com.dropbox.sync.android.NativeLib.throwFrom(NativeLib.java:242)
at com.dropbox.sync.android.NativeFileSystem.nativeOpenFile(Native Method)
at com.dropbox.sync.android.NativeFileSystem.nativeOpenFile(Native Method)
at com.dropbox.sync.android.NativeFileSystem.openFileHandle(NativeFileSystem.java:657)
at com.dropbox.sync.android.DbxFile.<init>(DbxFile.java:116)
at com.dropbox.sync.android.DbxFileSystem.open(DbxFileSystem.java:901)
at com.dropbox.sync.android.DbxFileSystem.create(DbxFileSystem.java:869)
at anywheresoftware.b4a.dropbox.DbxAccountManagerWrapper.getFile(DbxAccountManagerWrapper.java:150)
at anywheresoftware.b4a.dropbox.DbxAccountManagerWrapper.UploadFile(DbxAccountManagerWrapper.java:161)
at b4a.example.main._manager_accountready(main.java:410)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA$3.run(BA.java:320)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5434)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)

Full code:

B4X:
#Region  Project Attributes
   #ApplicationLabel: Dropbox
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: True
#End Region
Sub Process_Globals
  Private manager As DbxAccountManager
  Private key As String = "96kcdxy9w69cyvv"
  Private secret As String = "i0d433b0yskmiss"

End Sub

Sub Globals

   Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
  If FirstTime Then
  manager.Initialize(key, secret, "manager")
  End If
  Activity.LoadLayout("1")
End Sub

Sub Button1_Click
  manager.LinkAccount
End Sub

Sub Manager_AccountReady (Success As Boolean)
  Log("Account Ready: " & Success)
  If Success Then
  For Each FileInfo As DbxFileInfo In manager.ListFiles("/")
  Log(FileInfo.Name & ", " & FileInfo.IsFolder)
  Next
  End If
  manager.UploadFile("/", "books6.sqlite", File.DirRootExternal, "books6.sqlite")
End Sub

Sub Manager_DownloadCompleted (Success As Boolean, LocalDir As String, LocalFileName As String)
  Log("UploadCompleted: " & Success)
End Sub
What is the problem here that I can't upload to dropbox?
 

Cableguy

Expert
Licensed User
did you noticed this?
Resource File (new in V3.0)

Due to a bug/issue in Dropbox SDK we must set the app name with an XML file.
Create a file named strings.xml and put it under Objects\res\values.
The file content should be:
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">B4A Example</string>
</resources>
Change B4A Example to the correct app name. Set the file to be read-only.
 

Cableguy

Expert
Licensed User
Are you sure that you have upload rights to your dropbox account?
Basically the error message tells exactly that, that you have no upload rights
 

Lyndon Bermoy

Active Member
Licensed User
Are you sure that you have upload rights to your dropbox account?
Basically the error message tells exactly that, that you have no upload rights
I don't know exactly the upload rights but can you teach me sir how to have this upload rights?
 

Cableguy

Expert
Licensed User
Sorry, I have no experience with DropboxSync...try searching the forum and/or place a new question on the LIB thread itself
 

Cableguy

Expert
Licensed User
Anyway, since your original issue has been solved, you should start a new thread for your upload problem.
This way people will know what the thread is about. right now, it starts with something unrelated to your actual problem.
 
Top