cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right 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: 

Unexpected response code 400

Unexpected response code 400

ksprasad
New member | Level 2
Go to solution

Hi,

 

I had been able to successfully connect to dropbox using dropbox api. I am using the bundle dropbox-core-sdk 1.7.6 from maven repository. 

But since recently I am getting the below error from the same code.

 

Caused by: com.dropbox.core.DbxException$BadResponse: unexpected response code: 400
at com.dropbox.core.DbxClient$4.handle(DbxClient.java:274)
at com.dropbox.core.DbxClient$4.handle(DbxClient.java:270)
at com.dropbox.core.DbxRequestUtil.doGet(DbxRequestUtil.java:265)
at com.dropbox.core.DbxClient.doGet(DbxClient.java:1912)
at com.dropbox.core.DbxClient.getAccountInfo(DbxClient.java:270)
at org.apache.camel.dropbox.utils.DropboxApp.connect(DropboxApp.java:42)

 

Any idea what could be going wrong?

 

Below is the code:

final DropboxAppConfiguration appConfig = new DropboxAppConfiguration(appKey, appSecret,
                accessToken, host, port);
        final DropboxApp app = DropboxApp.create(appConfig);
        try {
            client = app.connect();
            logger.debug("Client connected: " + client.getAccountInfo().displayName);
        } catch (final FileNotFoundException e) {
            throw new IllegalArgumentException(e);
        } catch (final IOException e) {
            throw new IllegalArgumentException(e);
        } catch (final DbxException e) {
            throw new IllegalArgumentException(e);
        }

 

 

Regards,

ksprasad

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

The Dropbox Java SDK you're using (v1.7.6) is old and is using the now retired API v1. Calling API v1 will return a 400 error since it is now disabled.

 

You should instead use the latest version of the Dropbox Java SDK (currently v3.0.5), which uses API v2.

View solution in original post

11 Replies 11

Greg-DB
Dropbox Staff
Go to solution

The Dropbox Java SDK you're using (v1.7.6) is old and is using the now retired API v1. Calling API v1 will return a 400 error since it is now disabled.

 

You should instead use the latest version of the Dropbox Java SDK (currently v3.0.5), which uses API v2.

ksprasad
New member | Level 2
Go to solution

Thank you for the clarification.

Asakela
New member | Level 2
Go to solution
I AM not a developer - I am but a humble user. The answer doesn’t give me any clues about remedies to my problem. What can I do to make my connection work again?

Greg-DB
Dropbox Staff
Go to solution

@Asakela This is something the developer of the third party app would need to help with. I recommend you contact them for assistance. 

Tanny
Explorer | Level 3
Go to solution

Hola,

Yo engo el mismo problema, pero creo estar usando la versión más reciente de la api java de dropbox:

Captura.PNG

 

El código que estoy usando es:

package dropbox;

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

    
public class Main {

    public static void main(String[] args) throws IOException, DbxException{
        
        // 1) Provide app key and secret to the new DbxWebAuthNoRedirect object.
        final String APP_KEY = "asdf";
        final String APP_SECRET = "asdf";
        
        DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);
        
        DbxRequestConfig config = new DbxRequestConfig(
            "JavaTutorial/1.0", Locale.getDefault().toString());
        
        DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);
        
        // 2) start the OAuth flow
        String authorizeUrl = webAuth.start();
        // Have the user sign in and authorize your app.
        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();        
        
        DbxAuthFinish authFinish = webAuth.finish(code);
        String accessToken = authFinish.accessToken;

        DbxClient client = new DbxClient(config, accessToken);
        System.out.println("Linked account: " + client.getAccountInfo().email);        
        
    }
}

 

Y obtengo el siguiente error:

Exception in thread "main" com.dropbox.core.DbxException$BadResponse: unexpected response code: 400
	at com.dropbox.core.DbxClient$4.handle(DbxClient.java:350)
	at com.dropbox.core.DbxClient$4.handle(DbxClient.java:346)
	at com.dropbox.core.DbxRequestUtil.doGet(DbxRequestUtil.java:242)
	at com.dropbox.core.DbxClient.doGet(DbxClient.java:2167)
	at com.dropbox.core.DbxClient.getAccountInfo(DbxClient.java:346)
	at dropbox.Main.main(Main.java:49)
C:\Users\tnogales\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 2 seconds)

 

 

Me estoy rompiendo la cabeza y no encuentro la solución :disappointed_face:

 
 
 
 
 

Greg-DB
Dropbox Staff
Go to solution

@Tanny

De acuerdo con su captura de pantalla, también está usando una versión anterior del SDK (1.8.2). Actualice a la última versión (actualmente 3.0.8).

 

Como referencia, el reemplazo de getAccountInfo es getCurrentAccount.
---

Disculpe nuestras traducciones Nuestras traducciones fueron creadas usando un traductor en línea. Nos gustaría apoyar todos los idiomas, pero actualmente no estamos equipados para hacerlo. Aquí está la versión en inglés:

---

Please excuse our translations. Our translations were created using an online translator. We'd like to support every language, but we're not currently equipped to do so. Here is the English version:

---

According to your screenshot, you are also using an old version of the SDK (1.8.2). Please update to the latest version (currently 3.0.8).

 

For reference, the replacement for getAccountInfo is getCurrentAccount.

Tanny
Explorer | Level 3
Go to solution

Thank you!!! I did it and it worked !!!, but now I am getting other problem:

 

------------------------------------------------------------------------
Building dropbox 1.0-SNAPSHOT
------------------------------------------------------------------------

--- exec-maven-plugin:1.2.1:exec (default-cli) @ dropbox ---
Tanny Nogales
Exception in thread "main" com.dropbox.core.v2.files.ListFolderErrorException: Exception in 2/files/list_folder: {".tag":"path","path":"not_found"}
	at com.dropbox.core.v2.files.DbxUserFilesRequests.listFolder(DbxUserFilesRequests.java:1621)
	at com.dropbox.core.v2.files.DbxUserFilesRequests.listFolder(DbxUserFilesRequests.java:1662)
	at com.neges.dropbox.Main.main(Main.java:35)
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 3.336s
Finished at: Thu Jul 26 10:47:09 NDT 2018
Final Memory: 5M/123M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project dropbox: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

If you see, I am correctly getting the username "tanny nogales", but I can't retrieve the files in the folder "neges" :disappointed_face:

My code is the following:

 

package com.neges.dropbox;

import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.v2.DbxClientV2;
import com.dropbox.core.v2.files.FileMetadata;
import com.dropbox.core.v2.files.ListFolderResult;
import com.dropbox.core.v2.files.Metadata;
import com.dropbox.core.v2.users.FullAccount;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;

public class Main {
    private static final String ACCESS_TOKEN = "ASDFG";

    public static void main(String args[]) throws DbxException, FileNotFoundException, IOException {
        
        // Create Dropbox client
        DbxRequestConfig config = DbxRequestConfig.newBuilder("dropbox/java-tutorial").build();
        DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
        
        // Get current account info
        FullAccount account = client.users().getCurrentAccount();
        System.out.println(account.getName().getDisplayName());
        
        // Get files and folder metadata from Dropbox root directory
        ListFolderResult result = client.files().listFolder("/neges");
        while (true) {
            for (Metadata metadata : result.getEntries()) {
                System.out.println("Archivo: " + metadata.getPathLower());
            }

            if (!result.getHasMore()) {
                break;
            }

            result = client.files().listFolderContinue(result.getCursor());
            
        }
        
    }
}

Greg-DB
Dropbox Staff
Go to solution

@Tanny This 'path/not_found' error just means there is currently nothing at the specified path ("/neges" in your code) in the linked account.

 

A good way to check what is currently in the account is by listing the root, by using the path "" (an empty string).

Tanny
Explorer | Level 3
Go to solution

thank you a lot for the help!!

I did change de code line that you indicate me, but I does not retrieve the files:

 

 

ListFolderResult result = client.files().listFolder("");

 

 This is the output:

 

cd D:\Mis Documentos\Documents\NetBeansProjects\mavenproject1\dropbox; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_181" cmd /c "\"\"C:\\Program Files\\NetBeans 8.2\\java\\maven\\bin\\mvn.bat\" -Dexec.args=\"-classpath %classpath com.neges.dropbox.Main\" -Dexec.executable=\"C:\\Program Files\\Java\\jdk1.8.0_181\\bin\\java.exe\" -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.2\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\""
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...
                                                                        
------------------------------------------------------------------------
Building dropbox 1.0-SNAPSHOT
------------------------------------------------------------------------

--- exec-maven-plugin:1.2.1:exec (default-cli) @ dropbox ---
Tanny Nogales
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 8.381s
Finished at: Thu Aug 02 15:54:38 GMT-04:00 2018
Final Memory: 5M/123M
------------------------------------------------------------------------

 

My folder have the following files and subfolders:

 

Captura.PNG

And this is my app configuration:

 

Captura2.PNG

 

 

Please your help !! :slightly_smiling_face:

Need more support?
Who's talking

Top contributors to this post

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