Youtube Data Api stopping after 1000 results
Asked Answered
B

1

6

I have been trying to retrieve a list of all my subscribers for my youtube channel. I am using a query of the format:

https://content.googleapis.com/youtube/v3/subscriptions?mySubscribers=true&maxResults=50&part=subscriberSnippet&access_token=xxxx

However, after 1000 results (for example, 20 pages @ 50 per page, or 50 pages @ 20 per page) it stops. Within the documentation it say for myRecentSubscribers it should only retrieve 1000, but for mySubscribers there is no limit. Is there some unwritten limit?

Bopp answered 5/4, 2017 at 10:57 Comment(8)
I think the API is stopping you, and you would probably need a key to extend your quota. Googling around should reveal information about this.Lovins
I currently am using a key (removed from request to prevent malicious usage)Bopp
Is nextPageToken null after you have gotten the first 1000?Daniels
There is no nextPageToken in the request after that point, only prevPageTokenBopp
Can you include any error message after loading page 20?Cocaine
There isnt an error message - I just dont receive a nextPageToken on page 20, even though I have more than 20 pages of results.Bopp
@Bopp did you ever solve this?Nellnella
Hi I am struggling with the same problem, does anyone have any solution?Glandule
F
1

I just ran into the same issue w/ the following code:

import os

import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors

scopes = ["https://www.googleapis.com/auth/youtube.readonly"]

def main():
    # Disable OAuthlib's HTTPS verification when running locally.
    # *DO NOT* leave this option enabled in production.
    os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

    api_service_name = "youtube"
    api_version = "v3"
    client_secrets_file = "google_oauth_client_secret.json"

    # Get credentials and create an API client
    flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
        client_secrets_file, scopes)
    credentials = flow.run_console()
    youtube = googleapiclient.discovery.build(
        api_service_name, api_version, credentials=credentials)

    next_page_token = ''
    count = 0
    
    while next_page_token != None:
        print("Getting next page:", next_page_token, count)

        request = youtube.subscriptions().list(
            part="subscriberSnippet",
            maxResults=50,
            mySubscribers=True,
            pageToken=next_page_token
        )
        response = request.execute()
        next_page_token = response.get('nextPageToken')

        subscribers = response.get('items')
        for subscriber in subscribers:
            count += 1

    print('Total subscribers:', count)

if __name__ == "__main__":
    main()

This is the expected behavior if myRecentSubscribers=True but the list should continue with mySubscribers=True...

EDIT: Apparently this is a WONT FIX issue, and the documentation will likely eventually be updated to reflect.(https://issuetracker.google.com/issues/172325507)

Fernandez answered 20/11, 2020 at 20:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.