请告诉我我做错了什么,为什么我有403轴错误?我使用的是REACTIV17和AXIOS v0.27.2以及REACTION-CHAT-ENGINEV1.11.23。我如何解决这个问题?
这是我的进口商品
import React, { useState, useEffect, useContext } from "react";
import { useNavigate } from "react-router-dom";
import { ChatEngine } from "react-chat-engine";
import axios from "axios";
// Contexts
import { AuthContext } from "../contexts/AuthContextProvider";
这是主代码
const Chats = () => {
const [loading, setLoading] = useState(true);
const user = useContext(AuthContext);
const navigate = useNavigate();
useEffect(() => {
if (!user) {
navigate("/");
return;
}
axios
.get("https://api.chatengine.io/users/me/", {
headers: {
"Project-ID": "6e1e7008-716b-4141-a15c-836f05f720dd",
"User-Name": user.email,
"User-Secret": user.uid,
},
})
.then(() => {
setLoading(false);
})
.catch(() => {
let formdata = new FormData();
formdata.append("email", user.email);
formdata.append("username", user.email);
formdata.append("secret", user.uid);
getFile(user.photoURL).then((avatar) => {
formdata.append("avatar", avatar, avatar.name);
axios
.post("https://api.chatengine.io/users/", formdata, {
headers: {
"private-key":
"8094d378-e224-4558-97bf-35ca877f8f8e",
},
})
.then(() => setLoading(false))
.catch((error) => console.log(error));
});
});
}, [user, navigate]);
const getFile = async (url) => {
const response = await fetch(url);
const data = await response.blob();
return new File([data], "userPhoto.jpg", { type: "image/jpeg" });
};
if (!user || loading) return "Loading...";
return (
<div>
<ChatEngine
height="calc(100vh - 50px)"
projectID="6e1e7008-716b-4141-a15c-836f05f720dd"
userName={user.email}
userSecret={user.uid}
/>
</div>
);
};
export default Chats;
同样,当我点击API URL时,打开一个页面,并写上HTTP403禁止。一般来说,我没有访问API和聊天引擎。
谢谢你的帮助。
2条答案
按热度按时间hgncfbus1#
要连接到API服务器,您需要放置在项目 Jmeter 板的
API Keys
部分的私钥。然后将其用作axios
标头。您可以从官方帖子示例here中看到该示例dtcbnfnu2#
对于相同的代码,我也遇到了同样的问题。我通过更改VPN服务修复了它。请检查您的私钥并使用其他VPN服务进行测试。