Hey guys
I am trying to call the api with get method using token but I am getting CORS error
"Access to XMLHttpRequest at 'https://api.themoviedb.org/3/movie/popular' from origin 'http://127.0.0.1:5173' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."
This is my axios file
import axios from "axios";
const BASE_URL = "https://api.themoviedb.org/3";
const TMDB_TOKEN = import.meta.env.VITE_APP_TMDB_TOKEN;
const headers = {
Autherization: "bearer " + TMDB_TOKEN,
"Access-Control-Allow-Origin": "*",
"Content-Type": "text/plain",
};
export const fetchDataFromApi = async (url, params) => {
try {
const { data } = await axios.get(BASE_URL + url, {
headers,
params,
});
return data;
} catch (error) {
console.log(error);
return error;
}
};
This Is show I am calling the API
function App() {
useEffect(() => {
apiTesting();
}, []);
const apiTesting = () => {
fetchDataFromApi("/movie/popular").then((res) => console.log(res));
};
}
Can't find a movie or TV show? Login to create it.
Want to rate or add this item to a list?
Not a member?
Reply by ticao2 š§š· pt-BR
on March 24, 2023 at 4:56 AM
Maybe one of the questions below can help you.
CORS Issues
In some of the topics the problem was solved.
https://www.themoviedb.org/talk/5f55e3dd713ed40037f090d4
https://www.themoviedb.org/talk/5833110992514162cf03b7bd
https://www.themoviedb.org/talk/5c5dff05925141338cbce2db
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSNotSupportingCredentials
And this
https://www.themoviedb.org/talk/5f621eae93388b003864513c
https://www.themoviedb.org/talk/5eb07271a13533001b72740a
Axios Issues
https://www.themoviedb.org/talk/63e3d510db154f00812e67c6
https://www.themoviedb.org/talk/6037bbc2afa1b00043a76e2c
https://www.themoviedb.org/talk/5f621eae93388b003864513c
https://www.themoviedb.org/talk/5f55e3dd713ed40037f090d4
https://www.themoviedb.org/talk/5d5901d21749730017dd837a
https://www.themoviedb.org/talk/5bab86480e0a2664d4022f98