java - 如何使用curl调用dropbox api?

标签 java spring-boot dropbox

我有一个 Dropbox Controller

@RestController
@RequestMapping("dropbox")
public class DropboxController {
private static final Logger logger = LoggerFactory.getLogger(DropboxController.class);

@Autowired
DropboxService dropboxService;

@Autowired
DbxClientV2 dropboxClient;

@GetMapping("/list")
public List<Map<String, Object>> index(@RequestParam(value = "target", required = false, defaultValue = "") String target) throws Exception {
    return dropboxService.getFileList(target);
}

Springboot 应用程序

@SpringBootApplication
@ComponentScan(basePackages = {
        "aic.filestorage2.controller",
        "aic.filestorage2.service"
})

@Import({WebConfig.class})
public class DropboxExampleApplication {

    public static void main(String[] args) {
        SpringApplication.run(DropboxExampleApplication.class, args);
    }
@Bean("dropboxClient")
public DbxClientV2 dropboxClient() throws DbxException {
    String ACCESS_TOKEN = "ACCESS_TOKEN";
    DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial");
    DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
    return client;


}
}

使用curl时如何调用它? 当我尝试使用 dropbox/listlocalhost:8080/dropbox/list 时,它显示“无法解析主机”或第二个“status:404”

最佳答案

您对 RequestMapping 的定义似乎与我使用的不同。

试试这个:

@RestController
public class DropboxController {
private static final Logger logger = LoggerFactory.getLogger(DropboxController.class);

@Autowired
DropboxService dropboxService;

@Autowired
DbxClientV2 dropboxClient;

@RequestMapping(value="/dropbox/list", method = RequestMethod.GET)
public List<Map<String, Object>> index(@RequestParam(value = "target", required = false, defaultValue = "") String target) throws Exception {
    return dropboxService.getFileList(target);
}

你的curl命令看起来像这样:

curl -v http://localhost:8080/dropbox/list?target=myfile

关于java - 如何使用curl调用dropbox api?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58922704/

相关文章:

git - 将 .git 文件夹保留在保管箱之外

java - 如何避免小程序 "Do you want to run this application?"弹出消息

java - 将显式 Intent 从 ViewPagerAdapter 传递给 fragment

java - Spring boot,环境特定属性位置

spring - 如何在Spring Boot中更改crashHub端口

ubuntu - FFmpeg 无法在 Ubuntu 12.04 上访问 Dropbox 中的文件

javascript - Dropbox API : how to use the "path" value to display images

java - toString方法ArrayList简单递归

java - 为什么我的 Logback 生成的日志文件的每一行开头都有一个空格?

spring - 在Spring Boot中使用Web Client Mono获取API响应错误消息