The Movie Database Support Forum

Sorry for asking this question, im new to using api´s and i have seen alot of questions on here.


We are making a project, in which we want to fetch 1 movie by a genre chosen by the user. When the user then clicks the button, one movie will appear, if the user isn´t happy with the recommended movie, the user can fetch another movie.. is this possible with TMDB api. thx in advance

fetch('https://api.themoviedb.org/3/discover/movie?include_adult=false&include_video=false&language=en-US&page=1&sort_by=popularity.desc&with_genres=9648', options)
  .then(response => response.json())
  .then(data => {
    if (data.results && data.results.length > 0) {
      const randomIndex = Math.floor(Math.random() * data.results.length); // Generer en tilfældig indeks
      const tilfældigFilm = data.results[randomIndex]; // Hent den tilfældige film

      if (tilfældigFilm.id) {
        console.log('Tilfældig film ID:', tilfældigFilm.id);
      } else {
        console.log('Ingen ID fundet for den tilfældige film.');
      }
    } else {
      console.log('Ingen resultater fundet');
    }
  })
  .catch(err => console.error(err));

i have tried doing this, but for some reason it returns 2 movies in the consol log

Es fehlt ein Film oder eine Serie? Logge dich ein zum Ergänzen.

Allgemein

s Fokus auf Suchfeld
p Profil öffnen
esc Fenster schließen
? Tastenkürzel anzeigen

Videos

b Zurück
e Bearbeiten

Staffeln

Nächste Staffel
Vorherige Staffel

Episoden

Nächste Episode
Vorherige Episode

Bilder

a Poster oder Hintergrundbild hinzufügen

Editieren

t Sprachauswahl öffnen
ctrl+ s Speichern

Diskussionen

n Neue Diskussion erstellen
w Beobachten an / aus
p Diskussion öffentlich / privat
c Diskussion öffnen / schließen
a Diskussionsverlauf anzeigen
r Auf Diskussion antworten
l Letzte Antwort anzeigen
ctrl+ enter Senden
Nächste Seite
Vorherige Seite

Einstellungen

Diesen Eintrag bewerten oder zu einer Liste hinzufügen?

Anmelden