use of com.dropbox.core.DbxOAuth1Upgrader in project dropbox-sdk-java by dropbox.
the class Main method main.
public static void main(String[] args) throws IOException {
// Only display important log messages.
Logger.getLogger("").setLevel(Level.INFO);
Config cfg = parseArgs(args);
if (cfg == null) {
System.exit(1);
return;
}
// Read app info file (contains app key and app secret)
DbxAppInfo appInfo;
try {
appInfo = DbxAppInfo.Reader.readFromFile(cfg.appInfoFile);
} catch (JsonReader.FileLoadException ex) {
System.err.println("Error reading <app-info-file>: " + ex.getMessage());
System.exit(1);
return;
}
DbxOAuth1AccessToken oauth1AccessToken = new DbxOAuth1AccessToken(cfg.accessTokenKey, cfg.accessTokenSecret);
// Get an OAuth 2 access token.
DbxRequestConfig requestConfig = new DbxRequestConfig("examples-authorize");
DbxOAuth1Upgrader upgrader = new DbxOAuth1Upgrader(requestConfig, appInfo);
String oauth2AccessToken;
try {
oauth2AccessToken = upgrader.createOAuth2AccessToken(oauth1AccessToken);
} catch (DbxException ex) {
System.err.println("Error getting OAuth 2 access token: " + ex.getMessage());
System.exit(1);
return;
}
System.out.println("OAuth 2 access token obtained.");
DbxAuthInfo authInfo = new DbxAuthInfo(oauth2AccessToken, appInfo.getHost());
DbxAuthInfo.Writer.writeToStream(authInfo, System.out);
System.out.println();
// Disable the OAuth 1 access token.
if (cfg.disable) {
try {
upgrader.disableOAuth1AccessToken(oauth1AccessToken);
} catch (DbxException ex) {
System.err.println("Error disabling OAuth 1 access token: " + ex.getMessage());
System.exit(1);
return;
}
System.out.println("OAuth 1 access token disabled.");
}
}
Aggregations