LiveChatMessages: insert
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เพิ่มข้อความหรือแบบสำรวจลงในแชทสด
กรณีการใช้งานทั่วไป
ส่งคำขอ
คำขอ HTTP
POST https://www.googleapis.com/youtube/v3/liveChat/messages
การให้สิทธิ์
คำขอนี้ต้องมีการให้สิทธิ์ด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ อ่านเพิ่มเติมเกี่ยวกับการตรวจสอบสิทธิ์และการให้สิทธิ์ได้ที่การใช้การตรวจสอบสิทธิ์ OAuth 2.0
ขอบเขต |
https://www.googleapis.com/auth/youtube |
https://www.googleapis.com/auth/youtube.force-ssl |
พารามิเตอร์
ตารางต่อไปนี้แสดงพารามิเตอร์ที่การค้นหานี้รองรับ พารามิเตอร์ทั้งหมดที่แสดงคือพารามิเตอร์การค้นหา
พารามิเตอร์ |
พารามิเตอร์ที่จำเป็น |
part |
string
พารามิเตอร์ part มีไว้เพื่อวัตถุประสงค์ 2 อย่าง โดยจะระบุพร็อพเพอร์ตี้ที่การดำเนินการเขียนจะตั้งค่า รวมถึงพร็อพเพอร์ตี้ที่การตอบกลับของ 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 Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-01-02 UTC
[null,null,["อัปเดตล่าสุด 2025-01-02 UTC"],[],[],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."]]