You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
Zahra1
7 months agoExplorer | Level 3
oauth flow with spring boot
hello ,
I'm trying to integrate Dropbox with my Spring Boot application and enable the OAuth flow so users can use their Dropbox accounts within my application. However, it isn't working, and I'm s...
Zahra1
Explorer | Level 3
i've tried this :
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.v2.DbxClientV2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
public class DropboxService {
@Value("${dropbox.app.key}")
private String appKey;
@Value("${dropbox.app.secret}")
private String appSecret;
public DbxClientV2 getClient(String accessToken) {
DbxRequestConfig config = new DbxRequestConfig("APPFEATURE");
return new DbxClientV2(config, accessToken);
}
}
@Controller
public class DropboxController {
@Value("${dropbox.appKey}")
private String DROPBOX_APP_KEY;
@Value("${dropbox.appSecret}")
private String DROPBOX_APP_SECRET;
@Value("${dropbox.redirect.uri}")
private String DROPBOX_REDIRECT_URI;
private DbxWebAuth webAuth;
@GetMapping("/dropbox/auth")
public RedirectView authenticate() {
DbxRequestConfig config = DbxRequestConfig.newBuilder("dropbox/spring-boot-app").build();
DbxAppInfo appInfo = new DbxAppInfo(DROPBOX_APP_KEY, DROPBOX_APP_SECRET);
webAuth = new DbxWebAuth(config, appInfo);
DbxWebAuth.Request webAuthRequest = DbxWebAuth.newRequestBuilder()
.withRedirectUri(DROPBOX_REDIRECT_URI, new DbxStandardHttpRequestor.Config() ) //DbxStandardHttpRequestor.Config()
.build();
String authorizeUrl = webAuth.authorize(webAuthRequest);
return new RedirectView(authorizeUrl);
}
@GetMapping("/dropbox/callback")
public String callback(@RequestParam String code) {
try {
DbxAuthFinish authFinish = webAuth.finishFromCode(code);
String accessToken = authFinish.getAccessToken();
// Use the access token to create a DbxClientV2 instance
DbxRequestConfig config = DbxRequestConfig.newBuilder("dropbox/spring-boot-app").build();
DbxClientV2 client = new DbxClientV2(config, accessToken);
// Get the current account info as an example
FullAccount account = client.users().getCurrentAccount();
System.out.println("Account name: " + account.getName().getDisplayName());
return "redirect:/success";
} catch (DbxException ex) {
ex.printStackTrace();
return "redirect:/error";
}
}
}
Cannot resolve symbol 'DbxStandardHttpRequestor'
<dependency>
<groupId>com.dropbox.core</groupId>
<artifactId>dropbox-core-sdk</artifactId>
<version>5.4.0</version>
</dependency>
Здравко
7 months agoLegendary | Level 20
Zahra1 wrote:i've tried this :
...
DbxWebAuth.Request webAuthRequest = DbxWebAuth.newRequestBuilder()
.withRedirectUri(DROPBOX_REDIRECT_URI, new DbxStandardHttpRequestor.Config() ) //DbxStandardHttpRequestor.Config()
.build();
...Cannot resolve symbol 'DbxStandardHttpRequestor'
Hm... Why do you think that such a class should be there at all? Where you saw documentation about such an usage? 🤔
Just take a look on some of the examples and follow the idea there. 😉
By the way... you are using short lived token only! Keep in mind that for long term access you would need refresh token too if you need long term access.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,910 PostsLatest Activity: 3 days agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!