Служба підтримки The Movie Database

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 відповідь (на сторінці 1 із 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"
...

Не вдалося знайти фільм або серіал? Увійдіть, щоб додати.

Загальні

s відкрити панель пошуку
p відкрити меню профілю
esc закрити відкрите вікно
? відкрити вікно з гарячими клавішами

На сторінках медіа

b повернутися назад
e перейти до сторінки редагування

На сторінках сезонів шоу

(стрілка вправо) перейти до наступного сезону
(стрілка вліво) перейти до попереднього сезону

На сторінках серій шоу

(стрілка вправо) перейти до наступної серії
(стрілка вліво) перейти до попередньої серії

На всіх сторінках зображень

a відкрити вікно додавання зображення

На всіх сторінках редагування

t відкрити перемикач перекладів
ctrl+ s підтвердити форму

На сторінках обговорення

n створити нове обговорення
w змінити статус стеження
p перемикач публічно/приватно
c перемикач відкрито/закрито
a відкрити активність
r відповісти на обговорення
l перейти до останньої відповіді
ctrl+ enter підтвердити повідомлення
(стрілка вправо) наступна сторінка
(стрілка вліво) попередня сторінка

Налаштування

Хочете оцінити чи додати до списку?

Увійти

Немає облікового запису?

Приєднайтеся до спільноти