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
I am using a java, running on a google app engine server to complete this authentication.
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