Assistance de TMDB

I'm building an IMDB-like app for a college assignment in react native, and i'm having trouble with the multi search function.

when i have my endpoint search for movies, everything works just fine, but if i change the endpoint to search tv shows or multiple search, it returns empty for some reason.

would be glad if anyone might help.

6 réponses (sur la page 1 sur 1)

Jump to last post

Hi @Gunlol, to get assistance, please supply the api urls you are using. Replace your api key with a string like API_KEY or xxxxxxx.

const apiBaseUrl = `https://api.themoviedb.org/3`

as it says, this is the base URL

const searchMoviesEndpoint = `${apiBaseUrl}/search/movie?api_key=${apiKey}`

this is the URL end point i'm using. if i replace the movie with tv or multi (as in the documentation), i get an empty array as the result.

const apiCall = async (endpoint, params) => {
    const options = {
        method: 'GET',
        url:endpoint,
        params: params? params: {language: 'en-US'}
    }

    try {
        const response = await axios.request(options)
        return response.data

    }catch(error) {
        console.log("error: ", error)
        return {}
    }
}

this is the apiCall function i'm using

export const searchMovies = (params)=>{
    return apiCall(searchMoviesEndpoint, params);
}

this is the function for the search im using, that passes the parameters to the apiCall function above

small update, i managed to find out that i am getting a result back from the api call, but for some reason its not storing the result.

im using .map to go over the array that comes back from the api call, but i either have a problem with the .map function or the .length function.

im using react native expo, and the error im having is "cannot read property 'length' of undefined".

everything works fine when i have the endpoint set as: search/movie, but it doesn't work when i have it set as: search/tv or search/multi

Hi @robbie3999,would be glad if you could help me.

hi @Gunlol, I would be glad to help but I don't do javascript coding. I can provide you help with the tmdb api calls as needed.

A quick search of "cannot read property 'length' of undefined" for react/javascript shows this, it looks like you are trying to use the length property on something that is undefined or empty so check the value first before trying to use length.

Un film, une émission télévisée ou un artiste est introuvable ? Connectez-vous afin de créer une nouvelle fiche.

Général

s Mettre le curseur dans la barre de recherche
p Ouvrir le menu du profil
esc Fermer une fenêtre ouverte
? Ouvrir la fenêtre des raccourcis clavier

Sur les pages des médias

b Retour (ou vers le parent si faisable)
e Afficher la page de modification

Sur les pages des saisons des émissions télévisées

Afficher la saison suivante (flèche droite)
Afficher la saison précédente (flèche gauche)

Sur les pages des épisodes des émissions télévisées

Afficher l'épisode suivant (flèche droite)
Afficher l'épisode précédent (flèche gauche)

Sur toutes les pages des images / photos

a Ouvrir la fenêtre d'ajout d'image / photo

Sur toutes les pages de modifications

t Ouvrir le sélecteur de traduction
ctrl+ s Envoyer le formulaire

Sur les pages des discussions

n Créer une nouvelle discussion
w Basculer le statut de suivi
p Basculer publique / privée
c Basculer fermer / ouvrir
a Ouvrir l'activité
r Répondre à la discussion
l Afficher la dernière réponse
ctrl+ enter Envoyer votre message
Page suivante (flèche droite)
Page précédente (flèche gauche)

Paramètres

Vous souhaitez évaluer ou ajouter cet élément à une liste ?

Connexion