The Movie Database atbalsts

{ status_code: 7, status_message: "Invalid API key: You must be granted a valid key.", success: false }

Getting this but I have doubled checked my api key and copied it and pasted but although getting the same message..

URL using for my fetch() functions

const API_BASE_URL = "https://api.themoviedb.org/3";

const API_KEY = import.meta.VITE_TMDB_API_KEY;

const API_OPTIONS = {
  method: 'GET',
  headers: {
    Accept: "application/json",
    Authorization: `Bearer ${API_KEY}`
  }
}

function App() {
  const [searchTerm, setSearchTerm] = useState('');
  const [errorMessage, setErrorMessage] = useState(null);

  const fetchMovies = async () => {
    try {
      const endpoint = `${API_BASE_URL}/discover/movie?sort_by=popularity.desc`;
      const response = await fetch(endpoint, API_OPTIONS);

      if (!response.ok) {
        throw new Error("Sorry");
      } else {
        const data = await response.json();
        if (data.response == 'false') {
          setErrorMessage(data.error || 'failed to fetch movies.');
        }
        console.log(data);
      }
    } catch (error) {
      console.error(`Error fetching movies : ${error}`);
      setErrorMessage(`Error fetching movies, please try again later.`);
    }
  }

  useEffect(() => {
    fetchMovies();
  }, []);

2 replies (on page 1 of 1)

Jump to last post

Can you post here a real example of what the API Request sent to the TMDb servers is?
Maybe in the console.
Only then can we find out where the error is in the Request.

Problems with API Request

In order for someone to help you with API Request questions,
it is critical that you post here the API Request you are sending to the TMDb server.
Remember to replace your Key with MY_KEY , YOUR_KEY , THE_KEY , or something like that.

Not the programming code/script you used to build the API Request.
But the API Request that is sent to the TMDb server.
Or the API Request you would like to send.

@yadavkumarshivam,

I'm going to assume based on your variable names, that you're passing the API key in as a Bearer token. That is not supported. If you want to use header authentication, you need to pass your access token.

The docs outline this use case. You can read that here.

Nevari atrast filmu vai TV pārraidi? Jāpiesakās, lai to izveidotu.

Vispārējs

s fokusēties uz meklēšanas joslu
p atvērt profila izvēlni
esc aizvērt atvērtu logu
? atvērt īsinājumtaustiņu logu

Informācijas nesēju lapās

b atgriezties (vai pie vecākiem, ja nepieciešams)
e doties uz labošanas lapu

TV sezonas lapās

(labā bultiņa) pāriet uz nākamo sezonu
(kreisā bultiņa) pāriet uz iepriekšējo sezonu

TV sērijas lapās

(labā bultiņa) pāriet uz nākamo sēriju
(kreisā bultiņa) pāriet uz iepriekšējo sēriju

Visās attēlu lapās

a atvērt attēla pievienošanas logu

Visās labošanas lapās

t atvērt tulkošanas atlasītāju
ctrl+ s iesniegt veidlapu

Diskusiju lapās

n radīt jaunu diskusiju
w pārslēgt skatīšanās stāvokli
p pārslēgt publisko/privāto
c pārslēgt aizvērt/atvērt
a atklāta darbība
r atbilde uz diskusiju
l doties uz pēdējo atbildi
ctrl+ enter iesniegt savu ziņojumu
(labā bultiņa) nākamajā lapā
(kreisā bultiņa) iepriekšējā lapa

Iestatījumi

Vēlies novērtēt šo vienumu vai pievienot to sarakstam?

Pieteikties