3

Hello

I'm using TMDB Api and I got an error in my code saying that I have only 20 results out of 29. The reason is that the search function in TMDB did not return the second page of data. Here is the api search phrase (without my personal key):

https://api.themoviedb.org/3/search/movie?query=Avengers&api_key=API_KEY

And here is the data received: http://pastebin.com/MdpFz2Nx

As you can see there is only page 1 and at the bottom of the code it says there are 2 pages in total.

Is there some other way to receive the rest of the data or is it a mistake made by the API ?

Community
  • 1
  • 1
Aleksander Lipka
  • 354
  • 1
  • 9
  • 20

4 Answers4

11

You're looking for the page parameter.

https://api.themoviedb.org/3/search/movie?query=Avengers&api_key=API_KEY&page=2

Cheers.

Travis Bell
  • 204
  • 2
  • 7
1

Read in TMDB's forum on this link:

https://www.themoviedb.org/talk/5892db39c3a3686d10001a4d?language=en

You need to make another request to get next 20 results on next page

TMDB doesn't provide full search result without pagination in one API request (https://www.themoviedb.org/talk/55aa2a76c3a3682d63002fb1?language=en)

Sofyan Thayf
  • 1,322
  • 2
  • 14
  • 26
0

This is how I query 40 movies I'm using Axios btw.. you can do it on your own way

 async fetchPopularMovies(req, res) {

    let results = [];

    await axios
      .get(dBaseUrl + apiKey + "sort_by=popularity.desc&page=1")
      .then((value) => results.push(...value.data.results))
      .catch((err) => console.log(err));

    await axios
      .get(dBaseUrl + apiKey + "sort_by=popularity.desc&page=2")
      .then((value) => results.push(...value.data.results))
      .catch((err) => console.log(err));

    res.status(200).json(results);
  },
Koala
  • 352
  • 2
  • 7
  • 18
0

This you can try this is work for me in Angular

service.ts

searchbytextAndpageindex(data: any,pageNumber:number) 
{ 
    return this.http.get(`https://api.themoviedb.org/3/search/movie?api_key=<<key>>&language=en-US&query=${data}&page=${pageNumber}`,
        { params: { action: 'query', format: 'json', list: 'search', srsearch: data, origin: '*' } 
})

component.ts

async AllSearchdataFun(searchText: any, pageno: any) 
{
    this.loadings = true
    this.service.searchbytextAndpageindex(this.searchText,this.pageno).subscribe(async (searchdata: any) =>
    {
        await this.searchupcommingdta.push( ...searchdata.results);
        this.loadings = false
    })
}

component.ts

async onClickSearch()
{
    this.isshowSearhdata = true;
    this.isPagination = false;
    this.service.searchAndShowAllData(this.searchText).subscribe(async (res: any) => 
    {
        if (res.total_pages > 1) 
        {
            this.totalsearchpageIndex = res.total_pages;
            for (let i = 0; i <= this.totalsearchpageIndex; i++) 
            {
                this.AllSearchdataFun(this.searchText, i);
            }
        }
    })
}
Markus Meyer
  • 3,327
  • 10
  • 22
  • 35