Search code examples
pythonflaskyoutubeyoutube-data-apigoogle-api-python-client

Getting error when reporting a YouTube video


I am trying to report a YouTube video abuse from my Python Flask web application using the Google API client library. However, I am encountering an error when executing the youtube.videos().reportAbuse() method. The error message reads as follows:

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://youtube.googleapis.com/youtube/v3/videos/reportAbuse? returned "The request contained an unexpected value for the <code>reason_id</code> field, or a combination of the <code>reason_id</code> and <code>secondary_reason_id</code> fields.". Details: "[{'message': 'The request contained an unexpected value for the <code>reason_id</code> field, or a combination of the <code>reason_id</code> and <code>secondary_reason_id</code> fields.', 'domain': 'youtube.video', 'reason': 'invalidAbuseReason', 'location': 'body.reason_id', 'locationType': 'other'}]">

I have checked my code and confirmed that all the required parameters are being provided. How can I fix this error? Here is the relevant code block:

video_id = 'VIDEOID'

report = {
  'reasonId': 'SPAM',
  'videoId': video_id,
  'language': 'en'
}

youtube.videos().reportAbuse(body=report).execute()

Solution

  • Looking over the API docs for the reportAbuse API call:

    Specifies the reason that the video that is being reported for containing abusive content. Set the value to the appropriate videoAbuseReportReason resource's unique ID

    Which requires the unique ID of the reason. This is obtained from a list on videoAbuseReportReasons. Unfortunately I did a quick test API call and wasn't able to find the SPAM reason you mentioned to obtain the API for it. You'll have to pick one of the returned reasons from the API, including a possible secondary reason if it appears in the child nodes.