B4J Library Dropbox SDK V2

Discussion in 'B4J Libraries & Classes' started by DonManfred, May 20, 2018.

  1. DonManfred

    DonManfred Expert Licensed User

    Dropbox.png


    This is a begin of a wrap for the Dropbox JAVA SDK
    The Library is based on my v0.4 from the B4A Library. I´ve made an B4J Version out of it now.
    The Library is beta.

    It is a request for the community too to parcitipate to this project doing test or writing documentation for the objects.

    List of connected Tutorials:
    - Dropbox SDK V2 - Uploading big files to Dropbox
    - Dropbox SDK - get informed about changes in the used Dropbox

    Though it is a Link to a B4A Thread the same applies with the B4J Version so the Tutorial can be used.


    DropboxV2
    Comment:
    The Dropbox library allows you to communicate with Dropbox
    Author: DonManfred (wrapper)
    Version: 0.42 (wraps the SDK dropbox-core-sdk-3.0.7)

    Wrapped Objects so far
    • DbxAuth
    • DbxClientV2
    • DbxHost
    • Dimensions
    • DbxRequestConfig
    • DbxUserAuthRequests
    • DropboxV2
    • DbxUserFilesRequests
    • FileMetadata
    • FolderMetadata
    • FolderSharingInfo
    • GpsCoordinates
    • Mediainfo
    • MediaMetadata
    • Metadata
    • RelocationPath
    • DbxUserSharingRequests
    • MemberSelector
    • SharedFileMetadata
    • SharedFolderMetadata
    • SharedLinkMetadata
    • BasicAccount
    • FullAccount
    • DbxUserUsersRequests

    The Download will always be here in Post #1 of the Thread.

    Additional to the provided Library (xml and jar) you need to download:
    1. dropbox-core-sdk-3.0.7 Copy the file to your additional libraries folder.
    2. jackson-core-2.7.4.jar. Extract from the zip attached and copy the file to your additional libraries folder.
     

    Attached Files:

    Last edited: May 27, 2018
    jmon, Peter Simpson, vecino and 5 others like this.
  2. DonManfred

    DonManfred Expert Licensed User

    Example Code to use in an Server App (using your App ID and using a generated AccessToken. For now i do not know how to create the OAuth-Flow to use.

    Code:
    Sub Process_Globals
        
    Private fx As JFX
        
    Private MainForm As Form
        
    Dim Dropbox As DropboxV2
        
    Dim token As String
        
    Dim client As DbxClientV2
        
    Dim config As DbxRequestConfig
        
    Dim dbxFiles As DbxUserFilesRequests
        
    Dim dbxSharing As DbxUserSharingRequests
        
    Dim dbxUsers As DbxUserUsersRequests
        
    Dim clientId As String = "yourClientID"
        
    Dim token As String = "yourAccessToken"
        
    Private Button1 As Button
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
        MainForm.RootPane.LoadLayout(
    "Layout1"'Load the layout file.
        MainForm.Show
      
        config.Initialize(
    "",token,clientId,"de-de",5)
        
    Dim dbxhost As DbxHost
        dbxhost.Initialize
        client.Initialize(
    "Dropbox",config,token,dbxhost)
        dbxFiles = client.files
        dbxFiles.setEventname(
    "dbxFiles")
          
        dbxSharing = client.sharing
        dbxSharing.setEventname(
    "dbxSharing")
        dbxUsers = client.users
        dbxUsers.setEventname(
    "dbxUsers")
        Dropbox.Initialize(
    "")

        dbxFiles.listFolder(
    "/",False,True,False,False,True)

    End Sub
    Sub dbxFiles_UploadProgress(sessionId As Stringpath As String, filename As String, uploaded As Long, size As Long)
        
    Log($"${filename} -> ${NumberFormat(uploaded / 102400)} KB /${NumberFormat(size / 102400)} kb -> ${NumberFormat(100 * (uploaded / size), 02} - Session ${sessionId}"$)
    End Sub
    Sub dbxFiles_UploadFinished(success As Boolean, metaObj As Object, sessionId As String)
        
    Dim meta As FileMetadata = metaObj
        
    Log($"dbxFiles_UploadFinished(${success} Session ${sessionId} -> ${meta})"$)
    End Sub
    Sub dbxSharing_listFolders(success As Boolean, folders As List, error As String)
        
    Log($"dbxSharing_listFolders(${success}, ${folders.Size}, ${error})"$)
        
    If folders.Size > 0 Then
            
    For i = 0 To folders.Size-1
                
    Dim meta As SharedFolderMetadata = folders.Get(i)
                
    Log(meta.PathLower&" -> "& meta.Name)
            
    Next
        
    End If
    End Sub
    Sub dbxSharing_AddFileMember(success As Boolean, members As List, error As String)
        
    Log($"dbxSharing_listFolders(${success}, ${members.Size}, ${error})"$)
    End Sub
    Sub dbxSharing_listMountableFolders(success As Boolean, folders As List, error As String)
        
    Log($"dbxSharing_listFolders(${success}, ${folders.Size}, ${error})"$)
    End Sub
    Sub dbxSharing_listReceivedFiles(success As Boolean, receivedFiles As List, error As String)
        
    Log($"dbxSharing_listFolders(${success}, ${receivedFiles.Size}, ${error})"$)
      
    End Sub
    Sub dbxSharing_listSharedLinks(success As Boolean, sharedLinks As List, error As String)
        
    Log($"dbxSharing_listFolders(${success}, ${sharedLinks.Size}, ${error})"$)
    End Sub
    Sub dbxSharing_SharedFolderMetadata(success As Boolean, meta As SharedFolderMetadata, error As String)
        
    Log($"dbxSharing_listFolders(${success}, ${meta.toString}, ${error})"$)

    End Sub


    Sub dbxFiles_DownloadFinished(success As Boolean, meta As FileMetadata, sessionId As String)
        
    Log($"dbxFiles_DownloadFinished(${success}, ${meta}, ${sessionId})"$)
    End Sub
    Sub dbxFiles_listFolder(success As Boolean, content As List, error As String)
        
    Log($"dbxFiles_listFolders(${success}, ${content.Size}, ${error})"$)
        
    If content.Size > 0 Then
            
    For i = 0 To content.Size-1
                
    Dim meta As Metadata = content.Get(i)
                
    Log(meta.toString)
            
    Next
        
    End If
      
    End Sub
    Sub dbxFiles_CopyBatch(success As Boolean, meta As Map, error As String)
      
    End Sub
    Sub dbxFiles_CopyBatchCheck(success As Boolean, meta As Map, error As String)
      
    End Sub
    Sub dbxFiles_CopyReference(metainfo As Map)
      
    End Sub
    Sub dbxFiles_CreateFolder(success As Boolean, meta As FolderMetadata, error As String)
      
    End Sub
    Sub dbxFiles_ListRevisions(success As Boolean, meta As Map, error As String)
      
    End Sub
    Sub dbxFiles_MoveBatch(success As Boolean, meta As Map, error As String)
      
    End Sub
    Sub dbxFiles_MoveBatchCheck(success As Boolean, meta As Map, error As String)
      
    End Sub
    Sub dbxFiles_Restore(success As Boolean, meta As FileMetadata, error As String)
      
    End Sub

    Sub dbxUsers_getAccount(account As BasicAccount)
        
    Log($"dbxUsers_getAccount(${account})"$)
    End Sub
    Sub dbxUsers_getAccountBatch(batch As List)
      
    End Sub
    Sub dbxUsers_getCurrentAccount(account As FullAccount)
        
    Log($"dbxUsers_getCurrentAccount(${account})"$)
      
    End Sub
     
    Last edited: May 20, 2018
    clarionero and Erel like this.
  3. DonManfred

    DonManfred Expert Licensed User

    Uploading of Big Files

    Code:
    Sub Button1_Click
        
    Dim filename As String = "bremen.map"
        
    Dim path As String  = "E:\OSM"
        dbxFiles.uploadsession(
    path,filename,File.Size(path,filename),0,"","/testupload4j/", dbxFiles.WriteModeOVERWRITE)

    End Sub
    The Corresponding Events are as follows

    Code:
    Sub dbxFiles_UploadProgress(sessionId As Stringpath As String, filename As String, uploaded As Long, size As Long)
        
    Log($"${filename} -> ${NumberFormat(uploaded / 102400)} KB /${NumberFormat(size / 102400)} kb -> ${NumberFormat(100 * (uploaded / size), 02} - Session ${sessionId}"$)
    End Sub
    Sub dbxFiles_UploadFinished(success As Boolean, metaObj As Object, sessionId As String)
        
    Dim meta As FileMetadata = metaObj
        
    Log($"dbxFiles_UploadFinished(${success} Session ${sessionId} -> ${meta})"$)
    End Sub
    I tested it with a 2.4GB big File. It does work as expected :D

     
    Last edited: May 21, 2018
    jmon, peter93 and clarionero like this.
  4. DonManfred

    DonManfred Expert Licensed User

    Getting an AccessToken in behalf of the User who authenticate the Request. This is working only in Version 0.41+ of the Library.

    A json file with the clientId and the ClientSecret created which then can be used to generate a URL (authURL is a String).
    Code:
    Dim jgen As JSONGenerator
        jgen.Initialize(CreateMap(
    "key": clientId, "secret": clientSecret))
        
    File.WriteString(File.DirApp,"credentials.json",jgen.ToString)
        authURL = auth.Initialize(clientId,token,
    File.Combine(File.DirApp,"credentials.json"))
    You need to call this URL in a Webbrowser and follow the Authentication. At the end you´ll get an CODE. Copy the Code from the Webbrowser and use

    Code:
    Dim accesstoken As String = auth.AuthFinish(edtCode.Text,File.Combine(File.DirApp,"oauth.json"))
    to get the AccessToken which you then can use to Initialize the Library with the right "Credentials"
    Code:
    Dim accesstoken As String = auth.AuthFinish(edtCode.Text,File.Combine(File.DirApp,"oauth.json"))
        
    If accesstoken <> Null And accesstoken <> "" Then
            kvs.Put(
    "token",accesstoken)
            config.Initialize(
    "",accesstoken,clientId,"de-de",5)
            
    Dim dbxhost As DbxHost
            dbxhost.Initialize
            client.Initialize(
    "Dropbox",config,accesstoken,dbxhost)
            dbxFiles = client.files
            dbxFiles.setEventname(
    "dbxFiles")
            dbxSharing = client.sharing
            dbxSharing.setEventname(
    "dbxSharing")
            dbxUsers = client.users
            dbxUsers.setEventname(
    "dbxUsers")
            dbxFiles.listFolder(
    "",False,True,False,False,True)
        
    End If
     
    jmon, Erel and clarionero like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice