在阅读了官方 Dropbox 文档后,我设法编写了此代码以使用 DropBox 对用户进行身份验证并获取他的访问令牌。用户必须复制和粘贴令牌,我不喜欢这一步,我注意到一些开发人员可以使用类的withRedirect()方法DbxWebAuth。有一个使用重定向的示例,但它适用于 Web 应用程序,我无法将其调整为我的桌面应用程序。你们中有人与此有关吗?这是目前我的代码
public static void main(String[] args) throws Exception {
String accessToken = "";
String userLocale = null;
DbxRequestConfig requestConfig = new DbxRequestConfig("text-edit/0.1", userLocale);
DbxAppInfo appInfo = new DbxAppInfo("myString", "myString");
DbxWebAuth auth = new DbxWebAuth(requestConfig, appInfo);
DbxWebAuth.Request requestAuth = DbxWebAuth.newRequestBuilder().withNoRedirect().build();
String authorizeUrl = auth.authorize(requestAuth);
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.");
//Abrimos el enlace de autenticación del …Run Code Online (Sandbox Code Playgroud)