I am looking to write code that takes a video ID as input and retrieves the comments made on the corresponding video. Here's a link to the API docs. I tried this code
String videoId = "id";
YouTube.Comments.List list2 = youtube.comments().list(Arrays.asList("snippet"));
list2.setId(Arrays.asList(videoId));
list2.setKey(apiKey);
Comment c = list2.execute().getItems().get(0);
but I get an IndexOutOfBoundsException
on the last line because getItems
is returning an empty List
. I set videoId
as a valid YouTube video ID (one which I have already successfully been able to get video data like views, title, etc from), thinking that would work but clearly I was wrong. Unless I missed something I can't find anything in the docs for the Video
class about getting comment data, so that's why I'm turning to SO for help again.
EDIT: Per stvar's comment I tried changing the second line of the above code to
YouTube.CommentThreads.List list2 = youtube.commentThreads().list(Arrays.asList("snippet"));
and of course changed the type of c
to CommentThread
.
It is the CommentThreads
API I'm supposed to use, right? Either way, this is also returning an empty list...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…