cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Migration V1 to V2

Migration V1 to V2

JMagnat
Explorer | Level 3

Hi,

 

in V1 I simply use:

 

        Public Function write(myFile As String) As MetaData
            Dim Client As DropNetClient = New DropNetClient(Konstanten.DropboxAppKey, Konstanten.DropboxAppSecret)
Client.UseSandbox = True
            Client.GetToken()
            Process.Start(Client.BuildAuthorizeUrl())
            MessageBox.Show("Wait")
            Try
                Dim accessToken = Client.GetAccessToken()
                Dim myFilestream As FileStream = New FileStream(myFile, FileMode.Open, FileAccess.Read)
                Dim myReturn As MetaData = Client.UploadFile("/", System.IO.Path.GetFileName(myFile), myFilestream)
                myFilestream.Close()
                Return myReturn
            Catch ex As Exception
                Return Nothing
            End Try

        End Function

How can  I get the token in V2 without entering the code by the user??? 

15 Replies 15

Greg-DB
Dropbox Staff

For using API v2 from .NET, we recommend using the official Dropbox .NET SDK:

 

https://www.dropbox.com/developers/documentation/dotnet

 

The examples show how to handle authorization, e.g., using DropboxOAuth2Helper in SimpleBlogDemo:

 

https://github.com/dropbox/dropbox-sdk-dotnet/blob/master/Examples/SimpleBlogDemo/Controllers/HomeCo...

JMagnat
Explorer | Level 3

I had a look at all docus but I cant recognize in the example how I can get an accesstoken. I can generate the uri to show the authentification to the user but I cant receive a token.

Can you gibe me a hint?

Greg-DB
Dropbox Staff
The access token is retrieved a few lines later when the user is redirected back to the app after authorizing it here:

https://github.com/dropbox/dropbox-sdk-dotnet/blob/master/Examples/SimpleBlogDemo/Controllers/HomeCo...

JMagnat
Explorer | Level 3
I unterstand the following Workflow of this example...

I get the Uri To Show the User the authorisation Website. With the Parameter 'code' the User must Input the code manually into my app.
Is this right ?

Greg-DB
Dropbox Staff
If you use the "code" flow without a redirect URI, then yes, the user will have to manually copy and paste the authorization code into the app.

Using a redirect URI is recommended though, as shown in the example, as that will automatically pass the authorization code to your app, without the user copying/pasting it manually.

JMagnat
Explorer | Level 3

OK, I understand this. Thanx

 

Unfortunately my next question... 😉

 

Which format must the redirected uri be have? I must register this uri in the apps profile at dropbox. How can it be variable if my app runs on many different PCs?

Greg-DB
Dropbox Staff
As a security feature, each exact redirect URI does need to be pre-registered.

If you don't know the redirect URI ahead of time, one thing you may be able to do instead is to use one static redirect URI but encode the necessary information in the 'state' parameter, and decode it as necessary after the redirect back to your app, to handle it as necessary:

https://www.dropbox.com/developers/documentation/http/documentation#authorization

Alternatively, you could forgo using a redirect URI entirely. With the "code" flow, you can omit redirect_uri and have the user copy and paste the code manually. (Or, for the "token" flow, you can use https://www.dropbox.com/1/oauth2/display_token as the redirect URI and have the user copy and paste the access token.)

JMagnat
Explorer | Level 3

static redirect URI? What could this be? I think I must use a format like "https:\\aWebSide.com\anything" but this side doesnt exist and dropbox will send the users browser to them.

 

With ApiV1 the user connect to dropbox and my app get the token to download anything to dropbox. This isnt a web app.

 

 

JMagnat
Explorer | Level 3

I see this code in an example

 

                var builder = new UriBuilder(
                    Uri.UriSchemeHttps,
                    this.Request.Url.Host);

                builder.Path = "/Home/Auth";

                return builder.ToString();

But this generates no static Uri. How can I register this kind of redirectUri in the my dropbox app profile?

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    JMagnat Explorer | Level 3
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?