我正在尝试使用 Google API 客户端库从我的 Python Flask Web 应用程序报告 YouTube 视频滥用。但是,我在执行 youtube.videos().reportAbuse() 方法时遇到错误。报错信息如下:
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'}]">
我已经检查了我的代码并确认提供了所有必需的参数。我该如何解决这个错误?这是相关的代码块:
video_id = 'VIDEOID'
report = {
'reasonId': 'SPAM',
'videoId': video_id,
'language': 'en'
}
youtube.videos().reportAbuse(body=report).execute()
查看 reportAbuse API 调用的 API 文档:
指定被举报视频的原因 包含辱骂内容。设置合适的值 videoAbuseReportReason 资源的唯一 ID
需要原因的唯一ID。这是从 videoAbuseReportReasons 上的 list 获得的。不幸的是,我做了一个快速测试 API 调用,但无法找到您提到的为它获取 API 的垃圾邮件原因。您必须从 API 中选择一个返回的原因,包括可能出现在子节点中的次要原因。
响应似乎表明“垃圾邮件”不是有效的 VideoAbuseReportReason。你可以使用像
这样的东西request = youtube.videoAbuseReportReasons().list(part="snippet").execute()
检索允许值列表。