0

I have created a function to pull youtube's video data and load it into a data frame. I need to reverse the order so that I can append new videos to the end of the EXCEL as I'm not aware of code to append lines by adding a new row to the top. My code:

def get_video_details(youtube, video_ids):
    all_data = []
    for i in range(0, len(video_ids), 50):
        request = youtube.videos().list(
            part = 'snippet, statistics' , 
            id = ','.join(video_ids[i: i + 50]) ,
            #order = 'date'
        )
        response = request.execute()

        for video in response['items']:
            video_stats = dict(
                result_video_name = video['snippet']['title']  ,
                result_video_id = video['id'] ,                
                result_video_description = video['snippet']['description']  ,
                result_video_upload_time = video['snippet']['publishedAt']  ,
                result_video_views = video['statistics']['viewCount'] ,  
                result_video_likes = video['statistics']['likeCount'] ,  
                result_video_favorites = video['statistics']['favoriteCount'] ,  
                result_video_comments = video['statistics']['commentCount']  
                )
            all_data.append(video_stats)

    return all_data

I tried the order = 'date' option per YouTube's recommendation, but it's giving me a type error: TypeError: Got an unexpected keyword argument order

I followed a similar question (YouTube API: youtube.search().list won't order by date and Sorting Youtube API result from playlist) and it appears it's still not working or not really a feature. Is this still the case or has anyone found a work around?

If I put everything into a data frame, I get an output like this:

2921 - 2016-02-02T02:11:11Z

0 - 2022-12-12T21:10:11Z

I would like 0 to be the first video uploaded in 2016, and 2921 to the 0, uploaded today. I can use my data frame to flip them around, but the unique ID will not be changed.

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
  • `order` isn't a parameter from [YouTube Data API v3](https://developers.google.com/youtube/v3) [Videos: list](https://developers.google.com/youtube/v3/docs/videos/list) endpoint. – Benjamin Loison Dec 13 '22 at 00:21
  • the question is missing parts of code such as the imports... please add them so that there is sufficient code for a minimal reproducible example: https://stackoverflow.com/help/minimal-reproducible-example – D.L Dec 13 '22 at 00:59

0 Answers0