LiveChatMessages: insert
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Aggiunge un messaggio o un sondaggio a una chat live.
Casi d'uso comuni
Richiesta
Richiesta HTTP
POST https://www.googleapis.com/youtube/v3/liveChat/messages
Autorizzazione
Questa richiesta richiede l'autorizzazione con almeno uno dei seguenti ambiti. Per saperne di più sull'autenticazione e sull'autorizzazione, consulta Implementazione dell'autenticazione OAuth 2.0.
Ambito |
https://www.googleapis.com/auth/youtube |
https://www.googleapis.com/auth/youtube.force-ssl |
Parametri
La tabella seguente elenca i parametri supportati da questa query. Tutti i parametri elencati sono parametri di query.
Parametri |
Parametri obbligatori |
part |
string
Il parametro part ha due scopi. Identifica le proprietà che verranno impostate dall'operazione di scrittura e quelle che verranno incluse nella risposta dell'API. Imposta il valore del parametro su snippet . |
Corpo della richiesta
Fornisci una risorsa liveChatMessage nel corpo della richiesta.
Per questa risorsa, devi specificare i valori per queste proprietà
snippet.liveChatId
snippet.type
: scegli una delle seguenti opzioni: textMessageEvent
o pollEvent
- Se il tipo è
textMessageEvent
, includi snippet.textMessageDetails.messageText
- Se il tipo è
pollEvent
, includi snippet.pollDetails
con i seguenti valori:
snippet.pollDetails.metadata.options.questionText
- Elenco di
snippet.pollDetails.metadata.options.optionText
. Devi elencare almeno due elementi e non più di cinque. Gli elementi vengono visualizzati in sequenza nell'ordine in cui sono elencati.
Risposta
In caso di esito positivo, questo metodo restituisce una risorsa liveChatMessage nel corpo della risposta.
Errori
La seguente tabella identifica i messaggi di errore che l'API potrebbe restituire in risposta a una chiamata a questo metodo. Per maggiori dettagli, consulta la pagina API YouTube Live Streaming - Errori.
Tipo di errore |
Dettagli errore |
Descrizione |
forbidden (403) |
forbidden |
Non disponi delle autorizzazioni necessarie per creare il messaggio specificato. |
forbidden (403) |
liveChatDisabled |
La chat live specificata è stata disattivata dal proprietario, pertanto non è possibile aggiungere messaggi. |
forbidden (403) |
liveChatEnded |
La chat live specificata non è più attiva. |
invalidValue (400) |
messageTextInvalid |
Il testo del messaggio (snippet.textMessageDetails.messageText ) non è valido. |
notFound (404) |
liveChatNotFound |
La chat live identificata nella richiesta API non esiste. Questo errore si verifica se la chat è stata eliminata dal proprietario. |
required (400) |
liveChatIdRequired |
La risorsa liveChatMessage deve includere e specificare un valore per la proprietà snippet.liveChatId . |
required (400) |
messageTextRequired |
La risorsa liveChatMessage deve includere e specificare un valore per la proprietà snippet.textMessageDetails.messageText . |
required (400) |
typeRequired |
La risorsa liveChatMessage deve includere e specificare un valore per la proprietà snippet.type . Imposta il valore del parametro su text |
required (400) |
preconditionCheckFailed |
Esiste già un sondaggio attivo bloccato. |
rateLimitExceeded |
rateLimitExceeded |
L'utente ha pubblicato troppi messaggi di chat in un determinato periodo di tempo. |
Prova
Usa APIs Explorer per chiamare questa API e visualizzare la richiesta e la risposta dell'API.
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-01-02 UTC.
[null,null,["Ultimo aggiornamento 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."]]