Sai Kaneko
Sai Kaneko

Reputation: 13

Why the request for collecting video IDs failed even if we are using `nextPageToken` written on the previous API result?

I'm creating YouTube's metrics monitoring feature. But I faced one confusing point while using YouTube Data API.

I want to retrieve all video IDs of one YouTube channel. I'm using Lambda for this process.
Before API call, I'm refreshing the access token every time within the Lambda.
In order to retrieve video IDs, I used search#list with the following parameters:

Then, we can get the result like the following:

{
  "kind": "youtube#searchListResponse",
  "etag": "7d3zMRNK3SwAAdU_zX5Yo9oMezw",
  "nextPageToken": "SampleNextPageTokenParamXXX",
  "pageInfo": {
    "totalResults": 54,
    "resultsPerPage": 50
  },
  "items": [
    {
      "kind": "youtube#searchResult",
      "etag": "etag1",
      "id": {
        "kind": "youtube#video",
        "videoId": "sampleVideoId1"
      }
    },
    {
      "kind": "youtube#searchResult",
      "etag": "etag2",
      "id": {
        "kind": "youtube#video",
        "videoId": "sampleVideoId2"
      }
    },
    ...
}

Next, I tried to call the API with the following.

Then, we had two situations.

  1. [Success case] Can get the result
  2. [Failed case] Received the following result:
{
    "error": {
        "code": 400,
        "message": "Therequestspecifiesaninvalidpagetoken.",
        "errors": [
            {
                "message": "The request specifies an invalid page token.",
                "domain": "youtube.parameter",
                "reason": "invalidPageToken",
                "location": "pageToken",
                "locationType": "parameter"
            }
        ]
    }
}

I'm thinking this trouble happened from the access token's management solution, and this happened when the access token was inactivated by other processes working in parallel or Lambda's auto retrying process. But if you have any solution other than the viewpoint of tokens, could you tell us? Best Regards.

Upvotes: 1

Views: 90

Answers (1)

Taro TSUKAGOSHI
Taro TSUKAGOSHI

Reputation: 38

It seems there was a transient (known within Google) issue, where the nextPageToken was not working properly.

Google's staff reported that it was fixed: '400 invalidPageToken' error returned for a valid Next Page Token

Upvotes: 1

Related Questions