0
  • I used youtube data api returning search result. And to get more result, I used nextPageToken as param. => when a btn i made clicked, showing next page's 5 videos.
  • It actually works, but some next page results contain previous page's videos.
  • I expected if 3rd page videos are a, b, c, d, e, 4th page items are f, g, h, i, j.
  • but 4th page's like a, f, g, h, i or something. I'm not sure there is any rules or not.
search = async (input) => {
    const response = await fetch(
      `https://youtube.googleapis.com/youtube/v3/search?part=snippet&q=${input}&type=video&maxResults=15&key=${this.key}`,
      this.requestOptions
    );
    return await response.json();
  };

loadMore= async (searchToken, inputValue) => {
    const response = await fetch(
      `https://youtube.googleapis.com/youtube/v3/search?part=snippet&q=${inputValue}&type=video&pageToken=${searchToken}&key=${this.key}`,
      this.requestOptions
    );
    return await response.json();
  };

has anyone experienced and solved this problems?

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 02 '22 at 03:45
  • How are you calling async (searchToken, inputValue) are you sure your not sending prevPageToken – Linda Lawton - DaImTo May 02 '22 at 06:52
  • I checked it with console before, there is no problem. new items are not exactly same with previous page, but including some items. – RoAringTigeR May 02 '22 at 22:49
  • I am having this same problem. When I run the same query again, the appearance of duplicates is different, but the total number of videos returned is the same. This suggests that the duplicates are taking the place of other videos that should be in the list. – NewSites Nov 15 '22 at 02:35

1 Answers1

-1

The Youtube API returns the response in a paginated manner. This means that if you use the search functionality, your search results will be available on different pages where each page has a different page token. The maxResults parameter determines the number of results on each page(default=50). To tackle this problem and return new/different responses with each call , pass the nextPageToken to your next API call.

For example, if your first API call looks like this :

GET https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&q=cricket&key=[YOUR_API_KEY]

Your API response would look like :

{
"kind": "youtube#searchListResponse",
"etag": "uN1c33JfiFaPBemlxN5kH8lSaHw",
"nextPageToken": "CAoQAA",
"regionCode": "IN",
"pageInfo": {
  "totalResults": 1000000,
  "resultsPerPage": 10
},

To get the next 10 results of those 1000000, add pagetoken = nextPageToken to your query ,something like this :

GET https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&pageToken=CAoQAA&q=cricket&key=[YOUR_API_KEY]

AND VOILA!

{
"kind": "youtube#searchListResponse",
"etag": "NeaA5DLyr3YIaKdX5ZxETA3GfhY",
"nextPageToken": "CBQQAA",
"prevPageToken": "CAoQAQ",
"regionCode": "IN",
"pageInfo": {
  "totalResults": 1000000,
  "resultsPerPage": 10
}

YOU GET THE NEXT 10 RESULTS!

THE FIRST PAGE WOULD NOT HAVE ANY PAGETOKEN, SO THE FIRST API CALL NEEDS TO BE MADE WITHOUT PAGETOKEN PARAMETER

Refer to the official documentation for more details: https://developers.google.com/youtube/v3/docs/search/list

nasra404
  • 1
  • 1
  • This answer is useless. The guy said he's using the page token, so you're explaining in elaborate detail how to do something he is (and I am) already doing. – NewSites Nov 15 '22 at 02:36