Connect Twitch
Receive events from your Twitch channel in a macOS, Linux or Windows terminal: follows, subscriptions, bits, raids, channel point rewards and hype train levels.
1. Issue a key with the Twitch events scope
Section titled “1. Issue a key with the Twitch events scope”Before you start, check the Source conditions. In the «Секретные ключи» (Secret keys) section, click «Выпустить секретный ключ» (Issue secret key). Enter a name, tick «События Twitch» (Twitch events, twitch: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 dashboardSave the key in the DONATTY_TOKEN variable: how to do it.
2. Check the source
Section titled “2. Check the source”curl -s "https://api.donatty.com/v1/event-sources" -H "Authorization: Bearer $DONATTY_TOKEN"curl.exe -s "https://api.donatty.com/v1/event-sources" -H "Authorization: Bearer $env:DONATTY_TOKEN"Find the item with "platform": "TWITCH" in items. Before the first connection its status is IDLE: there are no stream connections yet. This is expected. No such item means the key has no twitch:read scope or no Twitch account is linked to your dashboard.
3. Connect to the twitch channel
Section titled “3. Connect to the twitch channel”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": ["twitch"]}}''{"data": {"channels": ["twitch"]}}' | curl.exe -N -X POST "https://api.donatty.com/v1/realtime/uni_http_stream" ` -H "Authorization: Bearer $env:DONATTY_TOKEN" -H "Content-Type: application/json" --data-binary "@-"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 twitch:str_… channel. For when collection starts and how long events take to arrive, see Source conditions.
Event data is in pub.data, for example twitch.follow when someone follows the channel. All types and their fields are in Twitch event formats.
4. Check that the source is ready
Section titled “4. Check that the source is ready”Repeat the request from step 2 in another terminal window and wait for the READY status. A status change also arrives in the stream as a source.status_changed event. For the meaning of each status, see Source status.
5. Read a gap
Section titled “5. Read a gap”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 Twitch. See Source conditions.
- How to reconnect and catch up on Twitch events: Stream and catch-up.
- All Twitch event types and their fields: Twitch event formats.
- The
twitchchannel, itstwitch:readscope and other available channels: Stream channels.