Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

API does not return all activities

$
0
0

I am trying to use pagination to retrieve all the video uploading activities in a YouTube channel:

import googleapiclient.discoveryapi_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'def main():    api_service_name = "youtube"    api_version = "v3"    youtube = googleapiclient.discovery.build(        api_service_name, api_version, developerKey=api_key)    next_page_token = 0    while next_page_token is not None:        request = youtube.activities().list(            part="snippet,contentDetails",            channelId="UCG-KntY7aVnIGXYEBQvmBAQ",            maxResults=50,            pageToken = None if next_page_token == 0 else next_page_token        )        response = request.execute()        for item in response['items']:            try:                id = item['contentDetails']['playlistItem']['resourceId']['videoId']                type = 'watched'            except:                id = item['contentDetails']['upload']['videoId']                type = 'upload'            if type == 'upload':                print(type, id, item['snippet']['title'])        next_page_token = response.get('nextPageToken')if __name__ == "__main__":    main()

For some reason, I get only 29 video uploads for a channel that has many more uploads than that.

Why is this happening?

EDIT I printed the dates of watching activities for my channel, i.e. item['snippet']['publishedAt'] and saw something very strange. Namely, activities of 2023 are followed by activities in 2020, which are followed by activities in 2016. It's like it took some recent activities, some activities a few years ago and some of the earliest ones. Somehow it decided to show only 29 activities in total, while it shows 79 for the channel of Thomas Frank (it's actually interesting why I am allowed to know which videos he watched)


Viewing all articles
Browse latest Browse all 3831

Trending Articles