While retrieving comments through YouTube API, I have come across a problem in which the code suggests that a video has disabled comments, thus returning an error, even though I can directly access tons of comments through the video’s link.
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
youtube = build('youtube', 'v3', developerKey= 'MYAPIKEY')
def fetch_comments(video_id):
response = youtube.videos().list(part="snippet", id = video_id).execute()
video_title = response['items'][0]['snippet']['title']
print(video_title)
vid_stats = youtube.videos().list(
part="statistics",
id=video_id
).execute()
comment_count = vid_stats.get("items")[0].get("statistics").get("commentCount")
print(comment_count)
try:
comments = []
response = youtube.commentThreads().list(
part="snippet",
videoId=video_id,
maxResults=100,
order="relevance",
).execute()
for item in response['items']:
comment = item['snippet']['topLevelComment']['snippet']['textDisplay']
print(comment)
comments.append(comment)
except HttpError as e:
print(f"An HTTP error occurred: {e}")
video_urls = ['https://www.youtube.com/watch?v=wLSUDSNqLgQ', 'https://www.youtube.com/watch?v=qAqXDZoa624','https://www.youtube.com/watch?v=7wBgcalM4c4' ]
for url in video_urls:
print(url)
video_id = url.split('=')[-1]
fetch_comments(video_id)
I developed a code to display 4 items: The video’s url, video’s title, the number of comments, and top 100 comments ordered by relevance, and the code succeeded in its duty except the fourth task: The code suggests that all three videos in the list (video_urls) has “has disabled comments,” while you can easily see that all three videos actually have their comments available.
Here’s what the output displays:
https://www.youtube.com/watch?v=wLSUDSNqLgQ
Everywhere (2017 Remaster)
432
An HTTP error occurred: <HttpError 403 when requesting https://youtube.googleapis.com/youtube/v3/commentThreads?part=snippet&videoId=wLSUDSNqLgQ&maxResults=100&order=relevance&key=AIzaSyDl-zKEBOx6TAeEZAnX3But1XunhDPOYNA&alt=json returned "The video identified by the <code><a href="/youtube/v3/docs/commentThreads/list#videoId">videoId</a></code> parameter has disabled comments.". Details: "[{'message': 'The video identified by the <code><a href="/youtube/v3/docs/commentThreads/list#videoId">videoId</a></code> parameter has disabled comments.', 'domain': 'youtube.commentThread', 'reason': 'commentsDisabled', 'location': 'videoId', 'locationType': 'parameter'}]">
Bette Davis Eyes
2435
An HTTP error occurred: <HttpError 403 when requesting https://youtube.googleapis.com/youtube/v3/commentThreads?part=snippet&videoId=qAqXDZoa624&maxResults=100&order=relevance&key=AIzaSyDl-zKEBOx6TAeEZAnX3But1XunhDPOYNA&alt=json returned "The video identified by the <code><a href="/youtube/v3/docs/commentThreads/list#videoId">videoId</a></code> parameter has disabled comments.". Details: "[{'message': 'The video identified by the <code><a href="/youtube/v3/docs/commentThreads/list#videoId">videoId</a></code> parameter has disabled comments.', 'domain': 'youtube.commentThread', 'reason': 'commentsDisabled', 'location': 'videoId', 'locationType': 'parameter'}]">
Time After Time
3263
I tried to develop the code to print the total number of comments to check whether making a reference to the comment itself is disabled, but as it turns out to be successful, I reckon it is the problem to do with the function of the code. Please somebody help me…
YouTube API commentsThreads() displays that a video disabled comments even though the video has tons of comments
While retrieving comments through YouTube API, I have come across a problem in which the code suggests that a video has disabled comments, thus returning an error, even though I can directly access tons of comments through the video’s link.
I developed a code to display 4 items: The video’s url, video’s title, the number of comments, and top 100 comments ordered by relevance, and the code succeeded in its duty except the fourth task: The code suggests that all three videos in the list (video_urls) has “has disabled comments,” while you can easily see that all three videos actually have their comments available.
Here’s what the output displays:
I tried to develop the code to print the total number of comments to check whether making a reference to the comment itself is disabled, but as it turns out to be successful, I reckon it is the problem to do with the function of the code. Please somebody help me…
Filed under: Kiến thức lập trình - @ 13:12
Thẻ: youtubecomments
« WinForms .NET 8 Textbox data binding to BindingSource in Designer: how? ⇐ More Pages ⇒ How can I fix this problem? I’m getting this error whenever I tried to run my code »