Imgur api 响应代码 403,服务器错误 429

Imgur api responding with code 403 with server error 429

我正在尝试使用带有 imgur api(反应)的 html 表单上传图片。

我在注册时选择了带有回调 URL 的 OAuth 2 授权 api。

问题是 api 无法使用错误 429(有时 net::ERR_HTTP2_PROTOCOL_ERROR)。

这是代码

const imageUpload = (e) => {
    console.log("called");
    var fileIn = e.target;
    var file = fileIn.files[0];
    if (file && file.size < 5e6) {
        const formData = new FormData();

        formData.append("image", file);
        fetch("https://api.imgur.com/3/image", {
            method: "POST",
            headers: {
                Authorization: "Client-ID //my client Id",
                Accept: "application/json",
            },
            body: formData,
        })
            .then((response) => response.json())
            .then((response) => {
                e.preventDefault();
                console.log(response);
                console.log(response.data.link);
                url_in = response.data.link;
            });
    } else {
        console.error("oversized file");
    }
}

这是输入标签代码

<input type="file" name="image" id="upload" onChange={imageUpload}></input>

我只需要上传图片的url

根据某人在 this answer 中发表的评论,我将 package.json 中的启动脚本更改为此 "start": "react-scripts start --host 0.0.0.0"。然后我将浏览器指向 http://0.0.0.0:3000/,然后我就能从 imgur.

得到回复