Suport de The Movie Database

I have a list of 500+ movies and currently I'm making a new API call for each movie.

const getMovie = async (tmdbId, apiKey) => {
    const url = `https://api.themoviedb.org/3/movie/${tmdbId}?api_key=${apiKey}&append_to_response=credits,release_dates`;
    const response = await fetch(url);
    const data = await response.json();
    return data;
};

The above getMovie function is being called for every single movie in my list. I was wondering if there is a way to get the data for several movies by, for instance, comma separating their TMDB IDs and making a single API call for more than one movie at a time.

To give you an example, Spotify offers a getAlbum service which returns the catalog information for a single album. It can be accessed as follows:

const getAlbum = async (albumID, accessToken) => {
    const url = `https://api.spotify.com/v1/albums/${albumID}?market=US`;
    const headers = { Authorization: `Bearer ${accessToken}` };
    const options = { method: 'GET', headers };
    const response = await fetch(url, options);
    const data = await response.json();
    return data;
};

However, Spotify also offers a getSeveralAlbums service which returns the catalog information for a maximum of 20 Albums at a time. It can be accessed as follows:

const getSeveralAlbums = async (albumIDs, accessToken) => {
    const albumIDsStr = albumIDs.slice(0, 20).join(',');
    const url = `https://api.spotify.com/v1/albums?ids=${albumIDsStr}&market=US`;
    const headers =  { Authorization: `Bearer ${accessToken}` };
    const options = { method: 'GET', headers };
    const response = await fetch(url, options);
    const data = await response.json();
    return data;
};

In the above function, albumIDsStr is a comma separated list of several Spotify IDs, e.g. 3mH6qwIy9crq0I9YQbOuDf,0k7ALIqqds5oGFtpMsaHLK,5HOHne1wzItQlIYmLXLYfZ etc. thus reducing the number of API calls required by 20x (since Spotify only allows a maximum of 20 albums per fetch request).

Any assistance would be much appreciated! Have a good day.

2 resposta (a les pàgines 1 de 1)

Jump to last post

Hi @ragonscreen,

While this is not possible at this time, we do already have a ticket for tracking this request here. You can watch/vote for it.

Cheers.

@travisbell Thank you so much for your reply, I will definitely be checking out the tracking request. Have a great day!

No trobeu una pel·lícula o una sèrie? Inicieu la sessió per a crear-la.

Global

s centra la barra de cerca
p obre el menú del perfil
esc tanca una finestra oberta
? obre la finestra de dreceres de teclat

A les pàgines de materials

b torna enrere (o la superior quan sigui aplicable)
e ves a la pàgina d’edició

A les pàgines de temporades

(fletxa dreta) ves a la temporada següent
(fletxa esquerra) ves a la temporada anterior

A les pàgines d'episodis

(fletxa dreta) ves a l'episodi següent
(fletxa esquerra) ves a l'episodi anterior

A totes les pàgines d'imatges

a obre la finestra d'afegir imatges

A totes les pàgines d'edició

t obre el selector de traducció
ctrl+ s envia el formulari

A les pàgines de debat

n crea un debat nou
w canvia l'estat de visualització
p canvia públic/privat
c tanca o obre
a obre activitat
r resposta al debat
l ves a la darrera resposta
ctrl+ enter envieu el vostre missatge
(fletxa dreta) pàgina següent
(fletxa esquerra) pàgina anterior

Configuracions

Desitgeu valorar o afegir aquest element a una llista?

Inicieu la sessió