The Movie Database -tuki

Hi,

I'm working on an app that generates Radom movies. I know that it's not possible with your API; to bypass that the app generates random numbers, then cross references that with the id's from movies. Via this methode it works, I don't know how to filter it with popular movies yet, but it works.

The issue is: I can't get the movie posters, genre and other stuff with it. Only the titels appear. Any idea what I'm doing wrong?

I'm using swiftUI btw:

ScrollView(.horizontal, showsIndicators: false) {
                    HStack {
                        ForEach(movieTitles.indices, id: \.self) { index in
                            Text(movieTitles[index])
                                .font(.headline)
                                .padding()
                        }
                    }
                }

                Button(action: {
                    var randomIds = [Int]()
                    while randomIds.count < 3 {
                        let randomId = Int.random(in: 1...803322)
                        if !randomIds.contains(randomId) {
                            randomIds.append(randomId)
                        }
                    }

                    MovieStore.shared.fetchMovies(from: .popular) { result in
                        switch result {
                        case .success(let response):
                            var movies = response.results
                            var titles = [String]()
                            for id in randomIds {
                                if let movie = movies.first(where: { $0.id == id }) {
                                    titles.append(movie.title)
                                    movies.removeAll(where: { $0.id == movie.id })
                                }
                            }
                            self.movieTitles = titles
                            self.movies = movies
                        case .failure(let error):
                            print(error.localizedDescription)
                        }
                    }
                }) {
                    Text("Get 3 Random Movies")
                        .font(.headline)
                        .foregroundColor(.white)
                        .padding()
                        .background(Color.blue)
                        .cornerRadius(10)
                }

                Spacer()

                ForEach(movieTitles.indices, id: \.self) { index in
                    HStack {
                        MoviePosterCard(movie: movies[index], imageLoader: ImageLoader())
                            .frame(width: 100, height: 60)
                            .onAppear {
                                self.imageLoader.loadImage(with: self.movies[index].posterURL)
                            }
                        Text(movieTitles[index])
                    }
                }

1 vastaus (sivulla 1, sivuja yhteensä 1)

Jump to last post

@Majinnn said:
Random movie generator
Hi,
I'm working on an app that generates Radom movies.
I know that it's not possible with your API;
to bypass that the app generates random numbers, then cross references that with the id's from movies.
Via this methode it works,
I don't know how to filter it with popular movies yet, but it works.
The issue is: I can't get the movie posters, genre and other stuff with it. Only the titels appear.
Any idea what I'm doing wrong?

What I do know is that when I make an API Request for Popular movies,
https://developers.themoviedb.org/3/movies/get-popular-movies
I get the following information on each of the movies:

page    1
results 
0   
adult   false
backdrop_path   "/hiHGRbyTcbZoLsYYkO4QiCLYe34.jpg"
genre_ids   
0   27
1   9648
2   53
id  758323
original_language   "en"
original_title  "The Pope's Exorcist"
overview    "Father Gabriele Amorth, …y tried to keep hidden."
popularity  6523.322
poster_path "/9JBEPLTPSm0d1mbEcLxULjJq9Eh.jpg"
release_date    "2023-04-05"
title   "The Pope's Exorcist"
video   false
vote_average    7.4
vote_count  554
1   
adult   false
backdrop_path   "/3CxUndGhUcZdt1Zggjdb2HkLLQX.jpg"
...

Etkö löydä elokuvaa tai TV-ohjelmaa? Kirjaudu sisään lisätäksesi se.

Koko sivustolla

s keskitä hakukenttään
p avaa profiilivalikko
esc sulje avoin ikkuna
? avaa pikanäppäinikkuna

Mediasivuilla

b palaa takaisin (tai hakemistoon mikäli mahdollista)
e siirry editoimaan sivua

TV-sarjan kausien sivuilla

(oikea nuolinäppäin) siirry seuraavaan kauteen
(vasen nuolinäppäin) siirry edelliseen kauteen

TV-sarjan jaksojen sivuilla

(oikea nuolinäppäin) siirry seuraavaan jaksoon
(vasen nuolinäppäin) siirry edelliseen jaksoon

Kaikilla kuvasivustoilla

a avaa "lisää kuva" ikkuna

Kaikilla muokkaus-sivuilla

t avaa kielivalinta
ctrl+ s Lähetä lomake

Keskustelu sivuilla

n luo uusi keskustelu
w vaihda seurannan asetus
p vaihda julkinen/yksityinen asetus
c vaihda avaa/sulje asetus
a avaa viimeaikainen toiminta
r vastaa keskusteluun
l siirry viimeisimpään vastaukseen
ctrl+ enter Lähetä viesti
(oikea nuolinäppäin) seuraava sivu
(vasen nuolinäppäin) edellinen sivu

Asetukset

Haluatko pisteyttää vai lisätä tämän nimikkeen listaan?

Kirjaudu

Ei rekisteröitynyt jäsen?

Rekisteröidy ja liity mukaan yhteisöön