I am trying to use YouTube API with python to extract data, it works well when I set the part including "status,contentDetails,topicDetails,player", but not working and shows the following response when setting part with 'monetizationDetails' or 'contentRating':
HttpError: <HttpError 403 when requesting https://youtube.googleapis.com/youtube/v3/videos?part=status%2CcontentDetails%2CtopicDetails%2Cplayer%2CmonetizationDetails&id=X2m-08cOAbc&key=AIzaSyAc2zl98eOHqRW8XE5oqDAyLYPe8UHBJ_M&alt=json returned "Access forbidden. The request may not be properly authorized.". Details: "[{'message': 'Access forbidden. The request may not be properly authorized.', 'domain': 'youtube.common', 'reason': 'forbidden'}]">
According to the document, I believe these parts(fields) should be available: https://developers.google.com/resources/api-libraries/documentation/youtube/v3/python/latest/youtube_v3.videos.html
My code:
from googleapiclient.discovery import buildapi_key = 'xxx'def video_comments(video_id): # empty list for storing reply replies = [] # creating youtube resource object youtube = build('youtube', 'v3', developerKey=api_key) # retrieve youtube video results video_response=youtube.videos().list( part="status,contentDetails,topicDetails,player,monetizationDetails", id=video_id ).execute() print(video_response)# Enter video idvideo_id = "X2m-08cOAbc"# Call functionvideo_comments(video_id)