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.