11

I am building a app that allows interaction with Dropbox. I have successfully authenticated to, and Dropbox is returning a key and template using it's default login page. However, when I try to use the login with Google option for Dropbox upon authenticating Dropbox returns a user key, however it doesn't return a template id, but instead a too many templates error.

Any help would be appreciated.

Here is my code

    public void authUrl(HttpServletRequest request)
{
    DbxWebAuth webAuth = new DbxWebAuth(requestConfig, appInfo);
    HttpSession session = request.getSession(true);
    String sessionKey = "dropbox-auth-csrf-token";
    DbxSessionStore csrfTokenStore = new DbxStandardSessionStore(session, sessionKey);

    DbxWebAuth.Request authRequest = DbxWebAuth.newRequestBuilder()
            .withRedirectUri(redirectUri, csrfTokenStore)
            .build();
    String authorizeUrl = webAuth.authorize(authRequest);
    url =authorizeUrl;
}
public String getTemplate()
{
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost post = new HttpPost("https://api.dropboxapi.com/2/file_properties/templates/add_for_user");
    post.addHeader("Authorization","Bearer "+code);
    post.addHeader("Content-Type", "application/json");
    try {
        HttpEntity entity = new StringEntity(json);
        post.setEntity(entity);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
    HttpResponse response = httpclient.execute(post);
    HttpEntity entity = response.getEntity();
    System.out.println(response.getStatusLine().getStatusCode());
    if (entity != null) {
        InputStream instream = entity.getContent();
        try {
            Scanner s = new Scanner(instream).useDelimiter("\\A");
            String result = s.hasNext() ? s.next() : "";
            System.out.println(result);
            System.err.println(result);
            return result;
        } finally {
            instream.close();
        }

    }
    }catch(Exception e)
    {
        e.printStackTrace();
    }

    return null;
}
public String authcode(HttpServletRequest request)
{
     DbxWebAuth auth = new DbxWebAuth(requestConfig, appInfo);
    String sessionKey = "dropbox-auth-csrf-token";
    HttpSession session = request.getSession(true);
     DbxSessionStore csrfTokenStore = new DbxStandardSessionStore(session, sessionKey);


     DbxAuthFinish authFinish;
     try {
         authFinish = auth.finishFromRedirect(redirectUri, csrfTokenStore, request.getParameterMap());
     } catch (DbxWebAuth.BadRequestException ex) {
         System.out.println("On /dropbox-auth-finish: Bad request: " + ex.getMessage());

         return "failed";
     } catch (DbxWebAuth.BadStateException ex) {
         System.out.println(ex.getMessage());
         // Send them back to the start of the auth flow.

         return "failed";
     } catch (DbxWebAuth.CsrfException ex) {
         System.out.println("On /dropbox-auth-finish: CSRF mismatch: " + ex.getMessage());
         //response.sendError(403, "Forbidden.");
         return "failed";
     } catch (DbxWebAuth.NotApprovedException ex) {
         // When Dropbox asked "Do you want to allow this app to access your
         // Dropbox account?", the user clicked "No".
         //...
         return "failed";
     } catch (DbxWebAuth.ProviderException ex) {
         System.out.println("On /dropbox-auth-finish: Auth failed: " + ex.getMessage());
         //response.sendError(503, "Error communicating with Dropbox.");
         return "failed";
     } catch (DbxException ex) {
         System.out.println("On /dropbox-auth-finish: Error getting token: " + ex.getMessage());
         //response.sendError(503, "Error communicating with Dropbox.");
         return "failed";
     }
     String accessToken = authFinish.getAccessToken();
     code =accessToken;
     return accessToken;
}

Notes

  1. I am using a java, running on a google app engine server to complete this authentication.

  2. The exact error text in the logs is

{"error_summary": "too_many_templates/...", "error": {".tag": "too_many_templates"}}

Along with a error 409.

If you need any more information feel free to ask

Austin
  • 726
  • 4
  • 22
  • 3
    Please edit your question and include a https://stackoverflow.com/help/mcve – Linda Lawton - DaImTo Apr 09 '18 at 06:10
  • 1
    It's unclear from your post what you're running exactly, or if you believe this error is incorrect, but [/2/file_properties/templates/add_for_user](https://www.dropbox.com/developers/documentation/http/documentation#file_properties-templates-add_for_user), for example, does document the `too_many_templates` error as "There are too many templates for the team". It sounds like there are just too many templates already created for that user/team already, so you can't add more. – Greg Apr 09 '18 at 13:49
  • @Greg That would make sense but I only get the error when authorizing using google login – Austin Apr 14 '18 at 14:54
  • In that case it sounds like you're probably signing in to different accounts. The one you're signing in to using the Google Sign In flow is apparently at the limit. – Greg Apr 16 '18 at 12:06

0 Answers0