LiveChatBans: insert
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
禁止特定用户参与实时聊天。此 API 请求必须由频道所有者或与禁播相关的直播聊天室的管理员授权。
常见使用场景
请求
HTTP 请求
POST https://www.googleapis.com/youtube/v3/liveChat/bans
授权
此请求需要获得以下至少一个范围的授权。如需详细了解身份验证和授权,请参阅实现 OAuth 2.0 身份验证。
范围 |
https://www.googleapis.com/auth/youtube |
https://www.googleapis.com/auth/youtube.force-ssl |
参数
下表列出了此查询支持的参数。列出的所有参数都是查询参数。
参数 |
必需参数 |
part |
string
在本操作中,part 参数有两个用途。它用于标识写入操作将设置的属性以及 API 响应返回的属性。将参数值设置为 snippet 。 |
请求正文
在请求正文中提供 liveChatBan 资源。
对于该资源:
-
您必须为以下属性指定值:
snippet.liveChatId
snippet.type
snippet.bannedUserDetails.channelId
-
您可以为以下属性设置值:
snippet.banDurationSeconds
错误
下表列出了该 API 在响应对此方法的调用时可能会返回的错误消息。如需了解详情,请参阅 YouTube Live Streaming API - 错误。
错误类型 |
错误详情 |
说明 |
forbidden (403) |
insufficientPermissions |
您没有必要的权限,无法将用户从指定的聊天中禁言。 |
forbidden (403) |
liveChatBanInsertionNotAllowed |
无法创建指定的禁播。如果请求尝试禁止聊天室所有者或其他管理员,可能会发生此错误。 |
invalidValue (400) |
invalidChannelId |
找不到指定的渠道 ID。 |
invalidValue (400) |
invalidLiveChatId |
请求中指定的 snippet.liveChatId 值无效。检查关联的 liveBroadcast 资源,确保您使用的是正确的值。 |
notFound (404) |
liveChatNotFound |
找不到指定的实时聊天。检查关联的 liveBroadcast 资源,确保您将 snippet.liveChatId 属性设置为正确的值。 |
notFound (404) |
liveChatUserNotFound |
找不到您尝试禁封的实时聊天用户。 |
required (400) |
bannedUserChannelIdRequired |
请求正文中提交的 liveChatBan 资源必须为 snippet.bannedUserDetails.channelId 属性指定值。 |
required (400) |
liveChatIdRequired |
请求正文中提交的 liveChatBan 资源必须为 snippet.liveChatId 属性指定值。 |
试试看!
使用 APIs Explorer 调用此 API,并查看 API 请求和响应。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-01-02。
[null,null,["最后更新时间 (UTC):2025-01-02。"],[],[],null,["# LiveChatBans: insert\n\nBans a specific user from participating in the live chat. The API request must be authorized by the channel owner or a moderator of the live chat associated with the ban.\n\nCommon use cases\n----------------\n\nThe list below shows common use cases for this method. Hover over a use case to see its description, or click on a use case to load sample parameter values in the APIs Explorer. You can open the [fullscreen APIs Explorer](#) to see code samples that dynamically update to reflect the parameter values entered in the Explorer.\n\nThe table below shows common use cases for this method. You can click on a use case name to load sample parameter values in the APIs Explorer. Or you can see code samples for a use case in the fullscreen APIs Explorer by clicking on the code icon below a use case name. In the fullscreen UI, you can update parameter and property values and the code samples will dynamically update to reflect the values you enter. \nThis method has one common use case, which is described below. The buttons below the description populate the APIs Explorer with sample values or open the fullscreen APIs Explorer to show code samples that use those values. The code samples also dynamically update if you change the values.\n\n\u003cbr /\u003e\n\nRequest\n-------\n\n### HTTP request\n\n```\nPOST https://www.googleapis.com/youtube/v3/liveChat/bans\n```\n\n### Authorization\n\nThis request requires authorization with at least one of the following scopes. To read more\nabout authentication and authorization, see\n[Implementing OAuth 2.0 authentication](/youtube/v3/live/authentication).\n\n| Scope |\n|-----------------------------------------------------|\n| `https://www.googleapis.com/auth/youtube` |\n| `https://www.googleapis.com/auth/youtube.force-ssl` |\n\n### Parameters\n\nThe following table lists the parameters that this query supports. All of the parameters listed are query parameters.\n\n| Parameters ||\n|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| **Required parameters** |||\n| `part` | `string` The **part** parameter serves two purposes in this operation. It identifies the properties that the write operation will set as well as the properties that the API response returns. Set the parameter value to `snippet`. |\n\n### Request body\n\nProvide a [liveChatBan resource](/youtube/v3/live/docs/liveChatBans#resource) in the request body.\nFor that resource:\n\n- You must specify a value for these properties:\n\n \u003cbr /\u003e\n\n - `snippet.liveChatId`\n - `snippet.type`\n - `snippet.bannedUserDetails.channelId`\n\n \u003cbr /\u003e\n\n- You can set values for these properties:\n\n \u003cbr /\u003e\n\n - `snippet.banDurationSeconds`\n\n \u003cbr /\u003e\n\nResponse\n--------\n\nIf successful, this method returns a [liveChatBan resource](/youtube/v3/live/docs/liveChatBans#resource) in the response body.\n\nErrors\n------\n\nThe following table identifies error messages that the API could return in response to a call to this method. For more details, see [YouTube Live Streaming API - Errors](/youtube/v3/live/docs/errors).\n\n| Error type | Error detail | Description |\n|----------------------|----------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `forbidden (403)` | `insufficientPermissions` | You do not have the necessary permissions to ban a user from the specified live chat. |\n| `forbidden (403)` | `liveChatBanInsertionNotAllowed` | The specified ban cannot be created. This error can occur if the request attempts to ban the chat owner or another moderator. |\n| `invalidValue (400)` | `invalidChannelId` | The specified channel ID cannot be found. |\n| `invalidValue (400)` | `invalidLiveChatId` | The `snippet.liveChatId` value specified in the request is invalid. Check the associated `liveBroadcast` resource to ensure that you have the correct value. |\n| `notFound (404)` | `liveChatNotFound` | The specified live chat cannot be found. Check the associated `liveBroadcast` resource to ensure that you are setting the `snippet.liveChatId` property to the correct value. |\n| `notFound (404)` | `liveChatUserNotFound` | The live chat user you are trying to ban cannot be found. |\n| `required (400)` | `bannedUserChannelIdRequired` | The `liveChatBan` resource submitted in the request body must specify a value for the `snippet.bannedUserDetails.channelId` property. |\n| `required (400)` | `liveChatIdRequired` | The `liveChatBan` resource submitted in the request body must specify a value for the `snippet.liveChatId` property. |\n\nTry it!\n-------\n\nUse the APIs Explorer to call this API and see the API request and response."]]