LiveChatMessages: insert
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
常见使用场景
请求
HTTP 请求
POST https://www.googleapis.com/youtube/v3/liveChat/messages
授权
此请求需要获得以下至少一个范围的授权。如需详细了解身份验证和授权,请参阅实现 OAuth 2.0 身份验证。
范围 |
https://www.googleapis.com/auth/youtube |
https://www.googleapis.com/auth/youtube.force-ssl |
参数
下表列出了此查询支持的参数。列出的所有参数都是查询参数。
参数 |
必需参数 |
part |
string
part 参数有两个用途。它用于标识写入操作将设置的属性,以及 API 响应将包含的属性。将参数值设置为 snippet 。 |
请求正文
在请求正文中提供 liveChatMessage 资源。
对于该资源,您必须为以下属性指定值
snippet.liveChatId
snippet.type
- 选择以下选项之一:textMessageEvent
或 pollEvent
- 如果类型为
textMessageEvent
,则添加 snippet.textMessageDetails.messageText
- 如果类型为
pollEvent
,请添加 snippet.pollDetails
,并使用以下值:
snippet.pollDetails.metadata.options.questionText
snippet.pollDetails.metadata.options.optionText
的列表。您必须列出至少 2 项,但不得超过 5 项。项会按列出的顺序依序显示。
错误
下表列出了该 API 在响应对此方法的调用时可能会返回的错误消息。如需了解详情,请参阅 YouTube Live Streaming API - 错误。
错误类型 |
错误详情 |
说明 |
forbidden (403) |
forbidden |
您没有创建指定消息所需的权限。 |
forbidden (403) |
liveChatDisabled |
指定的实时聊天已被所有者停用,这意味着无法向聊天中添加消息。 |
forbidden (403) |
liveChatEnded |
指定的实时聊天已结束。 |
invalidValue (400) |
messageTextInvalid |
消息文本 (snippet.textMessageDetails.messageText ) 无效。 |
notFound (404) |
liveChatNotFound |
API 请求中标识的实时聊天不存在。如果对话已被所有者删除,则会出现此错误。 |
required (400) |
liveChatIdRequired |
liveChatMessage 资源必须包含 snippet.liveChatId 属性并为其指定值。 |
required (400) |
messageTextRequired |
liveChatMessage 资源必须包含 snippet.textMessageDetails.messageText 属性并为其指定值。 |
required (400) |
typeRequired |
liveChatMessage 资源必须包含 snippet.type 属性并为其指定值。将参数值设置为 text |
required (400) |
preconditionCheckFailed |
已存在已固定的有效投票。 |
rateLimitExceeded |
rateLimitExceeded |
用户在给定时间范围内发布了过多聊天消息。 |
试试看!
使用 APIs Explorer 调用此 API,并查看 API 请求和响应。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-01-02。
[null,null,["最后更新时间 (UTC):2025-01-02。"],[],[],null,["# LiveChatMessages: insert\n\nAdds a message or a poll to a live chat.\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/messages\n```\n\n### Authorization\n\nThis request requires authorization with at least one of the following scopes. To read more about authentication and authorization, see [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. It identifies the properties that the write operation will set as well as the properties that the API response will include. Set the parameter value to `snippet`. |\n\n### Request body\n\nProvide a [liveChatMessage resource](/youtube/v3/live/docs/liveChatMessages#resource) in the request body.\nFor that resource, you must specify values for these properties\n\n- `snippet.liveChatId`\n- `snippet.type` - choose one of the following options: `textMessageEvent` or `pollEvent`\n- If type is `textMessageEvent`, include `snippet.textMessageDetails.messageText`\n- If type is `pollEvent`, include `snippet.pollDetails` with the following values:\n - `snippet.pollDetails.metadata.options.questionText`\n - List of `snippet.pollDetails.metadata.options.optionText`. You must list at least two items and no more than four items. Items are displayed sequentially in the order they're listed.\n\nResponse\n--------\n\nIf successful, this method returns a [liveChatMessage resource](/youtube/v3/live/docs/liveChatMessages#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)` | `forbidden` | You don't have the permissions required to create the specified message. |\n| `forbidden (403)` | `liveChatDisabled` | The specified live chat has been disabled by the owner, which means messages cannot be added to the chat. |\n| `forbidden (403)` | `liveChatEnded` | The specified live chat is no longer live. |\n| `invalidValue (400)` | `messageTextInvalid` | The message text (`snippet.textMessageDetails.messageText`) is not valid. |\n| `notFound (404)` | `liveChatNotFound` | The live chat identified in the API request does not exist. This error occurs if the chat has been deleted by the owner. |\n| `required (400)` | `liveChatIdRequired` | The [liveChatMessage resource](/youtube/v3/live/docs/liveChatMessages#resource) must include and specify a value for the `snippet.liveChatId` property. |\n| `required (400)` | `messageTextRequired` | The [liveChatMessage resource](/youtube/v3/live/docs/liveChatMessages#resource) must include and specify a value for the `snippet.textMessageDetails.messageText` property. |\n| `required (400)` | `typeRequired` | The [liveChatMessage resource](/youtube/v3/live/docs/liveChatMessages#resource) must include and specify a value for the `snippet.type` property. Set the parameter value to `text` |\n| `required (400)` | `preconditionCheckFailed` | A pinned active poll already exists. |\n| `rateLimitExceeded` | `rateLimitExceeded` | The user has posted too many chat messages in a given timeframe. |\n\nTry it!\n-------\n\nUse the APIs Explorer to call this API and see the API request and response."]]