I’m working on a PHP project where I need to fetch or generate a new streaming key for my Twitch channel through their API. I’ve managed to get the OAuth token working, but I’m stuck on finding the right endpoint to actually get the stream key.
The authentication part works fine and I get a valid token back. However, I can’t figure out what API endpoint I should call next to retrieve or generate a new stream key for my account. Does anyone know which URL I need to hit with my access token to get this information? I’ve been searching through the Twitch API docs but haven’t found the right approach yet.
hmm i think you cant actually get stream keys through the api anymore for security reasons. twitch removed that functionality a while back. you’ll need to grab it manually from your creator dashboard under settings > stream. the api only lets you check if a stream is live or get stream info, not the actual key itself.
Unfortunately you’re running into a brick wall here. Twitch locked down stream key access through their API several years ago and there’s no way around it. I went through the exact same frustration when building a streaming dashboard for our gaming community. What I ended up doing was creating a simple form in my PHP application where users input their stream key once after grabbing it from their Twitch dashboard. Then I store it encrypted in the database for future use. Not elegant, but it works reliably. Your OAuth implementation looks correct though, so you can still use that token for other Twitch API calls like checking stream status or getting channel information. Just not the stream key itself.
yeah as others mentioned, stream key access got axed from the api ages ago. but just a heads up - you’re using client credentials flow which wont work for user-specific data anyway. you’d need authorization code flow with user consent even if the endpoint existed. might wanna switch to user access tokens for other channel operations.
Just adding my experience from building a similar integration last year. The stream key retrieval was indeed removed from the API, but I found a reasonable workaround that might help your workflow. Instead of having users manually copy-paste their keys every time, I implemented a secure configuration page where they enter it once during initial setup. The key gets encrypted using PHP’s openssl_encrypt before database storage, and my application decrypts it when needed for streaming operations. This approach worked well for my broadcasting tool since most streamers don’t change their keys frequently anyway. Your OAuth code looks good for other API operations though - you can still pull stream analytics, follower counts, and channel metadata with that token structure.
The previous response is accurate - Twitch deprecated the stream key retrieval endpoints from their API years ago due to security concerns. Your authentication code is solid, but currently, there is no public API endpoint that will return stream keys.
I faced a similar issue when developing a stream management tool. The workaround was having users manually copy their stream key from the Twitch dashboard and paste it into my application settings. While not ideal for user experience, it’s the only reliable method available.
If programmatic access is essential, you could theoretically use browser automation tools like Selenium to scrape the dashboard, but that would violate Twitch’s terms of service and is quite fragile. The manual method is certainly the best option here.