尝试通过 Dropbox Javascript SDK 访问 Dropbox API 时出现错误 400

Error 400 when trying to access Dropbox API via Dropbox Javascript SDK

我有一个应用程序通过 Dropbox Javascript SDK 尝试下载文件。我不知道出了什么问题。通过 fetch 调用直接访问 Dropbox API 会带来同样的错误。 Dropbox API 文档说错误 400 是因为输入参数错误,但看起来我发送的内容没问题 - "Dropbox-API-Arg":"{\"path\":\"/1/price.xlsx\"}"

const Dropbox = require("dropbox").Dropbox;
import axios from "axios";
import fs = require("fs");
import { logger } from "./logger";

export class FileHandler {
    public async handle(path: string, token: string): Promise<void> {
        try {
            const dbx = new Dropbox({ fetch: axios, accessToken: token });
            dbx.filesDownload({ path })
                .then((data) => {
                    fs.writeFile(data.name, data.fileBinary, "binary", (err) => {
                        if (err) { throw err; }
                    });
                })
                .catch((error: any) => {
                    logger.error(error);
                    throw new Error(error);
                });

        } catch (err) {
            logger.error(err);
        }
    }
}

看起来只是一些请求参数有误,现在可以了:

public static async handle(path: string, token: string, userId: number, fileId: string): Promise<void> {
    try {
        axios.post("https://api.dropboxapi.com/2/files/get_temporary_link", { path }, {
            data: {
                path,
            },
            headers: {
                "Authorization": `Bearer ${token}`,
                "Content-Type": "application/json",
            },
        }).then((data) => FileHandler.readFile(data.data.link, data.data.metadata.name)
            .then(() => FileUtilities.parseFile(data.data.metadata.name, fileId)))
            .catch((err) => logger.error(err));
    } catch (err) {
        logger.error(err);
        UtilsRepository.findSupplierEmail(userId).then(data => {
            throw new MailingError(new MailObjectCannotReadFile(data[0].Email));
        });
    }
}