Hi!
I am trying to gather comments using the YouTube API. For this I use the example code provided on the Google developers site (I modified it a bit):
comments=[]
authors=[]
def get_comments(youtube, video_id):
results = youtube.commentThreads().list(
part="snippet",
videoId=video_id,
textFormat="plainText"
).execute()
for item in results["items"]:
comment = item["snippet"]["topLevelComment"]
author = comment["snippet"]["authorDisplayName"]
text = comment["snippet"]["textDisplay"]
comments.append(text)
authors.append(author)
return comments
As far as I understand it, this bit of code builds a function. So now, I want to use this function to gather the comments of a video. To this end I do:
video_id='1234videoid'
get_comments(youtube, video_id)
But this gives me an error: NameError: name 'youtube' is not defined.
Does anyone know what I should fill out instead of youtube? I should define it somehow, but I don't understand its function in this code. Any help would be greatly appreciated!