cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
If you’ve changed your email address, now's the perfect time to update it on your Dropbox account and we’re here to help! Learn more 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: 

Copy the authorization code.Where it is sufficient to copy?

Copy the authorization code.Where it is sufficient to copy?

u. katuhisa
New member | Level 2
 
3 Replies 3

u. katuhisa
New member | Level 2

>>> https://www.dropbox.com/developers-v1/core/start/java

If you run, you Copy the authorization code. Is displayed,
Where this code may be paste?

The complete code

For those keeping score at home, here's the full source to this guide. Make sure to create a working-draft.txt file to get it to work fully. Also remember to insert your app key and secret.

// Include the Dropbox SDK.
import com.dropbox.core.*;
import java.io.*;
import java.util.Locale;

public class Main {
    public static void main(String[] args) throws IOException, DbxException {
        // Get your app key and secret from the Dropbox developers website.
        final String APP_KEY = "INSERT_APP_KEY";
        final String APP_SECRET = "INSERT_APP_SECRET";

        DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);

        DbxRequestConfig config = new DbxRequestConfig("JavaTutorial/1.0",
            Locale.getDefault().toString());
        DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);

        // Have the user sign in and authorize your app.
        String authorizeUrl = webAuth.start();
        System.out.println("1. Go to: " + authorizeUrl);
        System.out.println("2. Click \"Allow\" (you might have to log in first)");
        System.out.println("3. Copy the authorization code.");
        String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();

        // This will fail if the user enters an invalid authorization code.
        DbxAuthFinish authFinish = webAuth.finish(code);
        String accessToken = authFinish.accessToken;

        DbxClient client = new DbxClient(config, accessToken);

        System.out.println("Linked account: " + client.getAccountInfo().displayName);

        File inputFile = new File("working-draft.txt");
        FileInputStream inputStream = new FileInputStream(inputFile);
        try {
            DbxEntry.File uploadedFile = client.uploadFile("/magnum-opus.txt",
                DbxWriteMode.add(), inputFile.length(), inputStream);
            System.out.println("Uploaded: " + uploadedFile.toString());
        } finally {
            inputStream.close();
        }

        DbxEntry.WithChildren listing = client.getMetadataWithChildren("/");
        System.out.println("Files in the root path:");
        for (DbxEntry child : listing.children) {
            System.out.println("	" + child.name + ": " + child.toString());
        }

        FileOutputStream outputStream = new FileOutputStream("magnum-opus.txt");
        try {
            DbxEntry.File downloadedFile = client.getFile("/magnum-opus.txt", null,
                outputStream);
            System.out.println("Metadata: " + downloadedFile.toString());
        } finally {
            outputStream.close();
        }
    }
}
 
 

u. katuhisa
New member | Level 2

></p>

Greg-DB
Dropbox Staff

When using the OAuth 2 app authorization flow without a redirect URI, as is being done in the sample and screenshot you posted, the authorization code is that string in the text box on the Dropbox site, and needs to be copied into the app to finish the flow. 

This line reads the authorization code from the console (where the user needs to paste it):

String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();

And then this line passes it to the finish method to finish the app authorization flow:

DbxAuthFinish authFinish = webAuth.finish(code);

The documentation for that method can be found here:

https://dropbox.github.io/dropbox-sdk-java/api-docs/v1.8.x/com/dropbox/core/DbxWebAuthNoRedirect.htm...

There's also an OAuth guide here that may serve as a useful reference:

https://www.dropbox.com/developers/reference/oauth-guide

 

 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    u. katuhisa New member | Level 2
What do Dropbox user levels mean?