Colin Harvie
Colin Harvie

Reputation: 21

Is pagination for Youtube API Channel Memberships (sponsors.list) broken?

I'm trying to paginate through a list of results using the youtube API for Channel Memberships (sponsors.list), but the paging and PageTokens don't seem to be working as they are supposed to.

I'm currently developing an application for a user to generate a list of all Members to their channel (using the api for sponsors.list: https://developers.google.com/youtube/v3/live/docs/sponsors/list)

I have a test account, and I've been able to successfully pull the list. However, the test account only has 5 memberships. Since the API can only pull a maximum of 50 results per page, I want to make sure that my app can account for the possibility that the channel will have 50+ sponsors.

So, I've set the results per page to give me just 1, theoretically giving me 5 pages I can then sift through to simulate 50+ members.

The problem arises when I try to page through the results... as the API says, I grab the nextPageToken from the results, and pass it in the next call in the pageToken parameter. However, when I do so, even when testing in the API explorer, I get back an empty list, and no nextPageToken for the next page.

{
 "kind": "youtube#sponsorListResponse",
 "etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/UCSC321uKOiUT6GNkcPmkqoH1sY\"",
 "pageInfo": {
  "totalResults": 0,
  "resultsPerPage": 0
 },
 "items": []
}

Additionally, if I pass a fake pageToken, the results come as if I'd passed no token at all, so it is at least recognizing the nextPageToken I'm passing it.

My google searches have failed me, other than just turning up pages talking about how the pagination is supposed to work... which it obviously isn't. Am I doing something wrong? Or is it indeed broken?

Edit

Here are the API calls I made. Initial member list pull (After getting the authorization token, etc).

'https://www.googleapis.com/youtube/v3/sponsors?part=snippet&filter=all&maxResults=1' \
  --header 'Authorization: Bearer [SECRET_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \

Which results in: (I've edited out sensitive info, like [CHANNEL_ID], etc).

{
 "kind": "youtube#sponsorListResponse",
 "etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/PRgb6wjx--gdhgTtZ1auDKOony0\"",
 "nextPageToken": "GLiawvDS6uEC",
 "pageInfo": {
  "totalResults": 5,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#sponsor",
   "etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/LoD6jhrr94l_4soca-7lx14kyRQ\"",
   "snippet": {
    "channelId": "[CHANNEL_ID]",
    "sponsorDetails": {
     "channelId": "[CHANNEL_ID]",
     "channelUrl": "[CHANNEL_URL]",
     "displayName": "[DISPLAY_NAME]",
     "profileImageUrl": "[PROFILE_IMAGE_URL]"
    },
    "sponsorSince": "2019-04-25T06:36:11.677Z"
   }
  }
 ]
}

So I grab the nextPageToken "GLiawvDS6uEC", and drop that into my next call in the pageToken field, as the API instructs.

  'https://www.googleapis.com/youtube/v3/sponsors?part=snippet&filter=all&maxResults=1&pageToken=GLiawvDS6uEC' \
  --header 'Authorization: Bearer [SECRET_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \

And wind up with this depressing result:

{
 "kind": "youtube#sponsorListResponse",
 "etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/UCSC321uKOiUT6GNkcPmkqoH1sY\"",
 "pageInfo": {
  "totalResults": 0,
  "resultsPerPage": 0
 },
 "items": []
}

Upvotes: 1

Views: 301

Answers (2)

Colin Harvie
Colin Harvie

Reputation: 21

So, turns out this was an actual problem with the API. Had a friend who knew someone at google, they looked into it, got the problem fixed! It works as intended now! Yay!

That said, if I hadn't had that connection, who knows if this would ever have been solved ;_;

Upvotes: 1

stvar
stvar

Reputation: 6975

As far as I can see, a nextPageToken of value GLiawvDS6uEC is invalid.

All the page tokens I came across were of a pattern described e.g. by Youtube Data API v3 pageToken for arbitrary page.

The API's documentation itself says nothing about how a page token should look like!

Maybe someone else has better inside on this issue. In any case, I suggest to file a report with Google.

Upvotes: 0

Related Questions