Reputation: 870
Using the Youtube V3 api, is it possible to check if comments are enabled/disabled for a video? The resource representation at for a video doesn't indicate a property that can be used to identify this, but I was wondering if people have used another way to find this out.
Upvotes: 3
Views: 1504
Reputation:
statistics.commentCount gives null only when we do not any comments and we may or may not have disable comments. if we already have comments and we disable the comments, then it gives the correct comments count. As far now i do not see an option for Checking if comments are enabled for a YouTube video through API.
Upvotes: 0
Reputation: 491
I actually came across a way to do this accidentally (via a bug in some of my code for collecting comments), and it's surprisingly simple.
It happens that the JSON objects returned by API v3 on videos with comments disabled don't have a statistics.commentCount
property.
Thus all you need to do is include part=statistics
in your request, and check for the statistics.commentCount
property in the response.
For example, in Python:
youtube = build(YOUTUBE_API_SERVICE_NAME,
YOUTUBE_API_VERSION,
developerKey=DEVELOPER_KEY)
vid_stats = youtube.videos().list(
part="statistics",
id=vidId
).execute()
comment_count = vid_stats.get("items")[0].get("statistics").get("commentCount")
comment_count
will get the value None
if comments are disabled
Upvotes: 2
Reputation: 12877
It was requested in Public issue tracker before, but it's not available in API yet.
Upvotes: 0