Youtube.subscriptions.list (api v3) - nextPageToken not available

I am trying to get all the channels from a subscription. But "nextPageToken" is not available.

The response should contain "nextPageToken":

(from developers.google.com - YouTube (v3) - Subscriptions: list)

{ "kind": "youtube#subscriptionListResponse", "etag": etag, "nextPageToken": string, "prevPageToken": string, "pageInfo": { "totalResults": integer, "resultsPerPage": integer }, "items": [ subscription Resource ] } 

This is my request:

 GET https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&maxResults=10&mine=true&key={YOUR_API_KEY} 

API - YouTube (v3) - Subscriptions.list:

https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.subscriptions.list?part=snippet&maxResults=10&mine=true

My answer:

 { "kind": "youtube#subscriptionListResponse", "etag": "\"XXXXX/XXXXX\"", "pageInfo": { "totalResults": 115, "resultsPerPage": 10 }, "items": [ ... 

Can you tell me why the next PageToken is missing, please?

+6
source share
3 answers

Here is the JS snippet that I came up with to create pageTokens, at least until 1024, I can not guarantee that it will lead to anything that can be higher, because I could not find any service that will receive me tokens for offsets> 450 to test my assumptions and assumptions.

 var d0 = "AEIMQUYcgkosw048"; var d1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var d2 = d1; var d1c = 0; var d2c = 0; var overflowSuffix = "Q"; var direction = "AA"; var d2OverflowCounter = 0; var pageSize = 50; for (i = 0; i < 1024; i++) { if (i % pageSize == 0) console.log("C" + d1.charAt((d1c / d0.length) % d1.length) + d0.charAt(i % d0.length) + overflowSuffix + direction, ":", i); if (++d1c % (1 << 8) == 0) d1c = 1 << 7; if (++d2c % (1 << 7) == 0) overflowSuffix = d2.charAt(++d2OverflowCounter) + "E"; } 

(check tools / developer console to see generated codes)

+3
source

I have a workaround for this. Please tell me if this helps.

The tokens seem to be the same for every page of the other Youtube V3 APIs, so I can use it to get all the subscription pages I need.

 tokens = ['CDIQAA','CGQQAA','CJYBEAA','CMgBEAA','CPoBEAA','CKwCEAA','CN4CEAA','CJADEAA','CMIDEAA','CPQDEAA','CKYEEAA', ...] 

You can use the ANOTHER Youtube API to get more page tokens if you need more. Just select one time item and write down the tokens for use in this API.

I just need to know when to stop ... so I checked when API calls do not return any feeds!

 @retry(stop_max_attempt_number=7) def get_subscription_page(self, channel_id, pageToken): print 'Retrieving subscription page using Youtube API (token: %s)' % pageToken res = self.youtube_data_api.subscriptions().list(part="id,snippet,contentDetails",channelId=channel_id, maxResults=50, pageToken=pageToken).execute() return res def get_subscriptions(self, channel_id): self.authorize(channel_id) subs = [] # Tokens to deal with api bug... # https://code.google.com/p/gdata-issues/issues/detail?id=7163 tokens = ['CDIQAA','CGQQAA','CJYBEAA','CMgBEAA','CPoBEAA','CKwCEAA','CN4CEAA','CJADEAA','CMIDEAA','CPQDEAA','CKYEEAA'] iPage = 0 pageToken = '' while True: res = self.get_subscription_page(channel_id, pageToken) channelIds = [] for channel in res['items']: channelIds.append(channel.get('snippet').get('resourceId').get('channelId')) pageToken = res.get('nextPageToken') # If no next page token is returned... it might be caused by a bug. # This workaroud will only have effect when the bug still lives. if not pageToken: if not channelIds: # Workaroud for this: https://code.google.com/p/gdata-issues/issues/detail?id=7163 print ' (Workaround due to API bug) No channels returned in this API call! Finished!' break else: pageToken = tokens[iPage] # get channel info for each channel ID channelsInfo = self.get_channel_info(channelIds) subs += channelsInfo print ' Itens already retrieved: %d ' % len(subs) iPage += 1 if args.debug: break if pageToken: continue print 'No more pages to retrieve!' break return subs 
+5
source

I have a script that runs every hour based on this Youtube API V3 and it stopped working 4 hours ago. NextPageToken is no longer available. Previously, it was available in the same way as in the first code you submitted.

+3
source

Source: https://habr.com/ru/post/987287/


All Articles