Soporte 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 respuestas (en la página 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 encuentras una película o serie? Inicia sesión para crearla:

Global

s centrar la barra de búsqueda
p abrir menú de perfil
esc cierra una ventana abierta
? abrir la ventana de atajos del teclado

En las páginas multimedia

b retrocede (o a padre cuando sea aplicable)
e ir a la página de edición

En las páginas de temporada de televisión

(flecha derecha) ir a la temporada siguiente
(flecha izquierda) ir a la temporada anterior

En las páginas de episodio de televisión

(flecha derecha) ir al episodio siguiente
(flecha izquierda) ir al episodio anterior

En todas las páginas de imágenes

a abrir la ventana de añadir imagen

En todas las páginas de edición

t abrir la sección de traducción
ctrl+ s enviar formulario

En las páginas de debate

n crear nuevo debate
w cambiar el estado de visualización
p cambiar público/privado
c cambiar cerrar/abrir
a abrir actividad
r responder al debate
l ir a la última respuesta
ctrl+ enter enviar tu mensaje
(flecha derecha) página siguiente
(flecha izquierda) página anterior

Configuraciones

¿Quieres puntuar o añadir este elemento a una lista?

Iniciar sesión