This tutorial will guide you through the process of setting up a developer account on Twitch, creating an application, obtaining a client ID and secret, generating a token, and importing a Node-RED flow to interact with the Twitch API to display Twitch followers number on a Ulanzi TC001.
Step 1: Setting Up a Developer Account on Twitch
-
Log in to Twitch
- Go to the Twitch website and log in to your account.
-
Navigate to the Developer Console
- Search for “Twitch developers” on Google and click the first link.
- In the top right corner, click on “Log in with Twitch” to authorize.
-
Enable Two-Factor Authentication
- Go to your Twitch account settings.
- Navigate to “Security and Privacy.”
- Enable two-factor authentication by providing your phone number and following the steps to scan the QR code with an authenticator app (Google Authenticator, Authy, etc.).
-
Register Your Application
- Click on “Register Your Application.”
- Provide a unique name for your application.
- Fill in the OAuth Redirect URLs with the necessary URL: https://api.twitch.tv/helix/channels/followers?broadcaster_id=XXXXXXXXX
- Use this website convert Twitch username to user ID to get the broadcaster ID.
- Select a category such as “Application Integration.”
- Choose “Confidential” for the application type.
- Complete the CAPTCHA and click “Create.”
-
Generate Client ID and Secret
- Once your application is created, navigate to the application management page.
- Copy the client ID to a secure location.
- Click “New Secret” to generate a client secret and copy it to a secure location.
Step 2: Generate a Token Using CURL
-
Open a terminal or command prompt.
-
Use the following command to generate an access token:
1 2 3
curl -X POST 'https://id.twitch.tv/oauth2/token' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'client_id=YOUR_CLIENT_ID&client_secret=YOUR_SECRET&grant_type=client_credentials'
Replace
YOUR_CLIENT_ID
with your actual client ID andYOUR_SECRET
with your actual client secret. -
The command will return a JSON object containing your access token:
1
{"access_token":"YOUR_TOKEN","expires_in":4869067,"token_type":"bearer"}
Step 3: Importing Node-RED Flow
-
Open Node-RED
- Ensure you have Node-RED installed in your Home Assistant or as a standalone instance.
- Open Node-RED from the Home Assistant interface or directly if standalone.
-
Import Flow
- Copy the JSON flow provided in this tutorial.
- In Node-RED, click on the hamburger menu (three horizontal lines) in the top right corner.
- Select “Import” and paste the JSON flow. Click “Import” again to add the flow.
-
Configure Flow
- Replace
YOUR_CLIENT_ID
,YOUR_TOKEN
, andYOUR_BROADCASTER_ID
in the flow with the actual values. - Replace
IP_ADDRESS_MQTT_BROKER
with the IP address of your MQTT broker.
- Replace
Twitch Node-RED Flow JSON
|
|
- Deploy the Flow
- Click “Deploy” in the top right corner of Node-RED to apply your changes.
- Ensure all nodes are correctly configured and connected.
Step 4: Validate the Setup
-
Trigger the Flow
- Manually trigger the inject node to test the flow.
- Check the debug nodes for any errors or outputs.
-
Verify MQTT Messages
- Ensure that the MQTT messages are being sent correctly to your broker.
By following these steps, you will have successfully set up a Twitch developer account, created an application, generated a token, and imported a Node-RED flow to interact with the Twitch API.