Please, help for a dummy ...

Apr 25, 2012 at 4:06 PM
Edited Apr 25, 2012 at 4:07 PM

Hi !

I'm not a programmer (just an old man), I have a small experience with but I like to learn.

I would like to write some code with this incredible library. Just an interface to upload/download from dropbox (for anyone who will be using my app with his dropbox account). My IDE is Visual Basic Express 2010.

After several test (trial & error) now I have some code which seems to be working.

Would like to know if it's correct. Any suggestion is more then welcome. Please just remeber that I'm a totally dummy, so I really appreciate if any idea is followed by examples (sorry, I just learn by examples ...).

Here is my simple code :


Imports AppLimit.CloudComputing.SharpBox
Imports AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox
Imports System.IO

Public Class Form1

    ' enter the consumer key and secret
    Dim ConsumerKey As String = "MyKey"
    Dim ConsumerSecret As String = "MySecret"

    ' get the config of dropbox
    Dim config As DropBoxConfiguration = TryCast(CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox), DropBoxConfiguration)
    Dim requestToken As DropBoxRequestToken

    Private Sub RequestButton1_Click(sender As System.Object, e As System.EventArgs) Handles RequestButton1.Click

        ' 0. set your own callback which will be called from DropBox after successful authorization
        config.AuthorizationCallBack = New Uri("")

        ' 1. create a request token
        requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(config, ConsumerKey, ConsumerSecret)

        ' 2. build the authorization url based on request
        Dim AuthorizationUrl As String = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(config, requestToken)

        ' 3. Redirect the user to the website of dropbox

    End Sub

    Private Sub SaveTokenButton2_Click(sender As System.Object, e As System.EventArgs) Handles SaveTokenButton2.Click

        ' 4. Exchange the request token into access token
        Dim accessToken As ICloudStorageAccessToken = DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(config, ConsumerKey, ConsumerSecret, requestToken)

        ' 5. Open the storage with the generated access token 
        Dim DropboxStorage As New CloudStorage()
        DropboxStorage.Open(config, accessToken)

        ' 6. write token for later use
        Dim tokenstream = DropboxStorage.SerializeSecurityToken(accessToken)
        Dim tokenfile As New FileStream("c:\MyToken.txt", FileMode.Create)

        ' 7. close the storage

    End Sub

    Private Sub DoUploadButton3_Click(sender As System.Object, e As System.EventArgs) Handles DoUploadButton3.Click

        ' A. open storage
        Dim DropboxStorage As New CloudStorage()
        Dim accessToken As ICloudStorageAccessToken

        ' B. load valid security token from file
        Using fs = File.Open("C:\MyToken.txt", FileMode.Open, FileAccess.Read, FileShare.None)
            accessToken = DropboxStorage.DeserializeSecurityToken(fs)
        End Using

        ' C. open the connection
        Dim storageToken = DropboxStorage.Open(config, accessToken)

        ' D. do whatever 
        Dim srcFile = Environment.ExpandEnvironmentVariables("C:\UploadMyFile.txt")
        DropboxStorage.UploadFile(srcFile, "/")

        ' E. close the connection

    End Sub

End Class

Many thanks indeed (I apologize also for my poor English)
Rick (Italy).