Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27514

Cant obtain Access Token. Unauthorized exception. Help?

$
0
0
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.


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("http://www.google.com")

        ' 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
        Process.Start(AuthorizationUrl)

    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)
        tokenstream.CopyTo(tokenfile)
        tokenfile.Close()

        ' 7. close the storage
        DropboxStorage.Close()

    End Sub


Viewing all articles
Browse latest Browse all 27514

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>