我有一个 api 键,但仍然出现 401 错误
I have an api key but still get a 401 error
我的网站无法连接到 OMDB api。这是一个 React 应用程序,通过 Netlify 部署。当我 运行 本地主机 3000 上的应用程序连接没问题。非常感谢任何帮助。
这就是我在 App.js 中设置 api 密钥的方式:
searchMovies = async (text) => {
try {
const API_KEY = process.env.REACT_APP_API_MOVIE_KEY;
const response = await axios.get(
`https://www.omdbapi.com/?apikey=${API_KEY}&`,
{
params: { s: text, type: 'movie' },
}
);
.env 文件如下所示:
REACT_APP_API_MOVIE_KEY=*****
Netlify 上的环境变量是这样的:
key: API_KEY value: *****
这是我得到的错误代码:
Failed to load resource: www.omdbapi.com/?apikey=undefined&&s=kate&type=movie:1 Failed to load
the server responded with a status of 401 ()
url 中缺少 IMDb ID:
例如 http://www.omdbapi.com/?i={imdb id}&apikey={api key}
Failed to load resource:
www.omdbapi.com/?apikey=undefined&&s=kate&type=movie:1 Failed to load
the server responded with a status of 401 ()
在此错误中,服务器告诉您您的 api 密钥未定义。请记录您的 api 密钥,然后检查
我的网站无法连接到 OMDB api。这是一个 React 应用程序,通过 Netlify 部署。当我 运行 本地主机 3000 上的应用程序连接没问题。非常感谢任何帮助。
这就是我在 App.js 中设置 api 密钥的方式:
searchMovies = async (text) => {
try {
const API_KEY = process.env.REACT_APP_API_MOVIE_KEY;
const response = await axios.get(
`https://www.omdbapi.com/?apikey=${API_KEY}&`,
{
params: { s: text, type: 'movie' },
}
);
.env 文件如下所示:
REACT_APP_API_MOVIE_KEY=*****
Netlify 上的环境变量是这样的:
key: API_KEY value: *****
这是我得到的错误代码:
Failed to load resource: www.omdbapi.com/?apikey=undefined&&s=kate&type=movie:1 Failed to load
the server responded with a status of 401 ()
url 中缺少 IMDb ID: 例如 http://www.omdbapi.com/?i={imdb id}&apikey={api key}
Failed to load resource: www.omdbapi.com/?apikey=undefined&&s=kate&type=movie:1 Failed to load the server responded with a status of 401 ()
在此错误中,服务器告诉您您的 api 密钥未定义。请记录您的 api 密钥,然后检查