import Results from '@/components/Results';
const API_KEY = process.env.API_KEY;
export default async function Home({ searchParams }) {
const genre = searchParams.genre || 'fetchTrending';
const res = await fetch(
`https://api.themoviedb.org/3${
genre === 'fetchTopRated' ? `/movie/top_rated` : `/trending/all/week`
}?api_key=${API_KEY}&language=en-US&page=1`,
{ next: { revalidate: 10000 } }
);
const data = await res.json();
if (!res.ok) {
throw new Error('Failed to fetch data');
}
const results = data.results;
return (
<div>
<Results results={results} />
</div>
);
}
*This is my page.js files code, plz help me to solve the issue of ' Failed to fetch data ' error, AND API INVALID error after execution and Testing the response of the key+URL with your testing link and also with an vs code extension ' Rapidapi Client ' API tester, I'm stuck with this API ERROR Sh$t from 2-3 weeks & Can't Further Progress in completion of my project *
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 OlegShved
on April 10, 2025 at 6:56 AM
Hi! How did you fix it? I have the same error, I'm doing a similar project.
Reply by ticao2 š§š· pt-BR
on April 10, 2025 at 8:12 AM
This user, @kunal@knk#0470 , has not accessed TMDb for a year.
I suggest you open a new thread explaining your problem.
If possible, show the API request you want to make that is causing the problem.
Reply by OlegShved
on April 10, 2025 at 8:16 AM
@ticao2 const res = await fetch(
https://api.themoviedb.org/3${ genre === 'fetchTopRated' ?
/movie/top_rated:
/trending/all/week}?api_key=${API_KEY}&language=en-US&page=1
, )Reply by ticao2 š§š· pt-BR
on April 10, 2025 at 8:18 AM
As I said in my previous comment...