Skip to content

Connect YouTube

Receive events from your YouTube channel in a macOS, Linux or Windows terminal: new subscribers, channel members, Super Chats and Super Stickers.

1. Issue a key with the YouTube events scope

Section titled “1. Issue a key with the YouTube events scope”

Before you start, check the Source conditions. In the «Секретные ключи» (Secret keys) section, click «Выпустить секретный ключ» (Issue secret key). Enter a name, tick «События YouTube» (YouTube events, youtube:read), choose an expiration period and click «Выпустить ключ» (Issue key).

To find out which keys support this scope, see Secret key scopes.

Open Developers in your dashboard

Save the key in the DONATTY_TOKEN variable: how to do it.

Terminal
curl -s "https://api.donatty.com/v1/event-sources" -H "Authorization: Bearer $DONATTY_TOKEN"

Find the items with "platform": "YOUTUBE" in items: one for each linked channel. Before the first connection their status is IDLE: there are no stream connections yet. This is expected. No such items means the key has no youtube:read scope or no YouTube channel is linked to your dashboard.

Terminal
curl -N -X POST "https://api.donatty.com/v1/realtime/uni_http_stream" \
-H "Authorization: Bearer $DONATTY_TOKEN" -H "Content-Type: application/json" -d '{"data": {"channels": ["youtube"]}}'

In PowerShell, pipe the request body through | to preserve the JSON quotes when calling curl.exe.

The command reads the stream until you press Ctrl+C. In the first line, subs contains the youtube:str_… channel. While the connection is open, Donatty polls YouTube for your channel. For what happens after the first poll and how long events take to arrive, see Source conditions.

Event data is in pub.data, for example youtube.super_chat when a viewer sends a Super Chat. The exact amount in the viewer’s currency is in details.amount: ExactMoney. All types and their fields are in YouTube event formats.

Repeat the request from step 2 in another terminal window and wait for the READY status: polling works. READY does not mean an event has already arrived: a new event shows up in the stream from step 3 when it happens on the channel. A status change also arrives in the stream as a source.status_changed event. For the meaning of each status and unavailableTypes, see Source status; for event types that YouTube may not provide, see Source conditions.

After a long disconnection, use the Platform events method to catch up. For commands and steps, see the Stream and catch-up example. For recovery requirements, see History and catch-up. REST cannot return events that Donatty did not receive from YouTube. See Source conditions.