I use the Dropbox API for java and i have this problem with the token expiration..
First, get the token like everybody else:
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();
And i replace the code to get the token:
DbxAuthFinish authFinish = webAuth.finish(REPLACE_CODE);
String accessToken = authFinish.accessToken;
So far,everything ok, but after a time, when i try again, boom!:
HTTP Error 401 Unauthorized : Token Expired.
I read documentation and search in ALL the network, and the only answer that i get is: the token never expired.
So, what i'm doing wrong? And is any way to re-authorize automatically?
Thanks!
It looks like you're trying to reuse an authorization code (the thing you pass in to webAuth.finish
) instead of an access token (the thing you get from authFinish.accessToken
). I would expect that to fail the second time you try it, since those codes should only be used once.
The access token itself, though, effectively doesn't expire. That said, users can certainly revoke your app's permission, so you should consider the possibility of receiving a 401, as described in the Core API docs: https://www.dropbox.com/developers/core/docs.