دعم الموقع

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 ردود (على هذه الصفحة 1 من 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!

لم تجد الفلم أو المسلسل ؟ سجل دخولك و انشئها

عام

s ركز شريط البحث
p افتح قائمة الملف الشخصي
esc اغلق النافذة المفتوحة
? افتح نافذة اختصارات لوحة المفاتيح

على كافة صفحات الوسائط

b ارجع للخلف (او للصفحة الام عند التطبيق)
e انتقل لصفحة التعديل

على كافة صفحات موسم المسلسل

(السهم الايمن) انتقل للموسم التالي
(السهم الايسر) انتقل للموسم السابق

على كافة صفحات حلقة المسلسل

(السهم الايمن) انتقل للحلقة التالية
(السهم الايسر) انتقل للحلقة السابقة

على كافة صفحات الصور

a افتح صفحة اضافة الصورة

على كافة صفحات التعديل

t افتح محدد الترجمة
ctrl+ s ارسال النموذج

على صفحات المناقشة

n انشى نقاش جديد
w تبديل حالة المتابعة
p تبديل عام / خاص
c تبديل اغلاق / فتح
a افتح الانشطة
r رد على النقاش
l انتقل لأخر رد
ctrl+ enter أرسل رسالتك
(السهم الايمن) الصفحة التالية
(السهم الايسر) الصفحة السابقة

الاعدادات

هل تريد تقييم او اضافة هذا العنصر للقائمة؟

تسجيل الدخول