„The Movie Database“ palaikymas

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

Negalite rasti filmo ar TV laidos? Prisijunkite, kad sukurtumėte.

Bendras

s susitelkti į paieškos juostą
p profilio meniu
esc uždarykite atidarytą langą
? spartieji klavišai

Medijų puslapiuose

b grįžkite atgal (arba tėvams leidus)
e į redagavimo puslapį

TV sezono puslapiuose

(dešinė rodyklė) sekantis sezonas
(kairė rodyklė) ankstesnis sezonas

TV epizodo puslapiuose

(dešinė rodyklė) sekantis epizodas
(kairė rodyklė) ankstesnis epizodas

Visuose atvaizdžio puslapiuose

a atverti atvaizdžio pridėjimo langą

Visuose redagavimo puslapiuose

t vertimo parinktys
ctrl+ s pateikti formą

Diskusijų puslapiuose

n sukurti naują diskusiją
w perjungti peržiūros būseną
p perjungti viešasis / privatus
c perjungti uždaryti / atidaryti
a peržiūrėti aktyvumą
r atsakyti į pokalbį
l į paskutinį atsakymą
ctrl+ enter pateikti pranešimą
(dešinė rodyklė) sekantis puslapis
(kairė rodyklė) ankstesnis puslapis

Nustatymai

Norite įvertinti ar įtraukti šį elementą į sąrašą?

Prisijungti