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
- 如果 type 為
pollEvent
,請加入 snippet.pollDetails
,並使用下列值:
snippet.pollDetails.metadata.options.questionText
snippet.pollDetails.metadata.options.optionText
清單。您必須列出至少兩項,最多五項。項目會依照列出的順序依序顯示。
錯誤
下表列出 API 在回應對此方法的呼叫時可能傳回的錯誤訊息。詳情請參閱「YouTube Live Streaming API - Errors」。
錯誤類型 |
錯誤詳細資料 |
說明 |
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 要求和回應。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-01-02 (世界標準時間)。
[null,null,["上次更新時間: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."]]