Thanks for this API!
Running into a strange bug... The following code works great for a list of movies, but for a list of TV shows, it returns the correct total_results
and object_ids
, but the results
array is empty.
Any idea why?
const fetch = require(`node-fetch`);
const Bottleneck = require(`bottleneck`);
const limiter = new Bottleneck({
reservoir: 40, // max requests
reservoirRefreshAmount: 40,
reservoirRefreshInterval: 10 * 1000, // time span
maxConcurrent: 1,
minTime: 10000 / 40 // avg MS per request
});
async function fetchTMDBListData(listId) {
let items = [];
let page = 1;
let totalPages;
async function fetch20Items() {
return await fetch(
`https://api.themoviedb.org/4/list/${listId}?sort_by=release_date.desc&page=${page}`,
{
headers: {
Accept: "application/json",
Authorization: `Bearer ${process.env.TMDB_READ_ACCESS_TOKEN}`
}
}
);
}
do {
try {
const response = await limiter.schedule(() => fetch20Items());
const data = await response.json();
totalPages = data.total_pages;
items.push(...data.results);
} catch (error) {
console.log("fetchTMDBListData error", error);
}
page++;
} while (page <= totalPages);
return Promise.all(items);
}
Can't find a movie or TV show? Login to create it.
Want to rate or add this item to a list?
Not a member?
Reply by ooloth
on November 7, 2019 at 10:22 PM
Nevermind! It was just the
sort_by
value.When querying the
tv
api,release_date
needs to becomeprimary_release_date
.Reply by Travis Bell
on November 8, 2019 at 10:23 AM
Hi @ooloth,
Yes, I believe the common date sort field I setup for lists is
primary_release_date
. Otherwise on TV, I always usefirst_air_date
. This is the same as how discover works.Anyways, happy to hear you sorted it.