Cant obtain Access Token. Unauthorized exception.

May 7, 2013 at 9:14 PM
It seems that Dropbox wont let me obtain access token. Any suggestions?
Steps 0-3 work fine but it stops on step 4 and gives and 'unauthorized exception' warning. I have entered the correct
consumer key and secret and it seems to accept those fine and wants to connect the users account to the application.
However it hangs on step 4.

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

        ' 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
May 27, 2013 at 8:48 AM
Edited May 27, 2013 at 10:25 AM
After step 3, you should wait for the user to grant permission on the Dropox interface before continuing with Step 4. So it's recommended you save the token and do it as two separate steps.