Home > other >  How to assign this list of id's to video.list (id = ) and make it return more than 50 results?
How to assign this list of id's to video.list (id = ) and make it return more than 50 results?

Time:09-12

I create a script that covert YouTube video links into id's:

print(link_data.head)

I have 100 rows in 1 column

0    tSbA3J_enCA
1    jWOgDXnqxi8
2    uNZH7zlZ-b4
3    SgXwnKTHRdM
4    TuN_vVoEqf4
..           ...
96   SxSQ29eUyfo
97   dmPb-gZgaBk
98   fA1Jzm9fK38
99   HNdQ6yXQmLE
100  Z8FdzNwSC3c

How to assign thislink_data to id_list_data and make it return more than 50 results?

id_list_data = 

results = youtube.videos().list(id = id_list_data, part ='snippet').execute()
for result in results.get('items', []):
        print(result ['id'])
        print(result ['snippet']['channelTitle'])
        print(result ['snippet']['title'])
        print(result ['snippet']['description'])

CodePudding user response:

As YouTube Data API v3 Videos: list endpoint has a maxResults of 50, you have to call youtube.videos().list(...) with at most 50 ids.

maxResults = 50

for i in range(ceil(len(link_data.head) / maxResults)):
    id_list_data = link_data.head[i * maxResults:(i   1) * maxResults]
    results = youtube.videos().list(id = id_list_data, part ='snippet').execute()
    for result in results.get('items', []):
            print(result ['id'])
            print(result ['snippet']['channelTitle'])
            print(result ['snippet']['title'])
            print(result ['snippet']['description'])
  • Related