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.
找不到电影或节目?登录并创建它吧。
Travis Bell 的回复
于 2024 年 03 月 11 日 5:55下午
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.
ragonscreen 的回复
于 2024 年 03 月 12 日 3:46上午
@travisbell Thank you so much for your reply, I will definitely be checking out the tracking request. Have a great day!