I need help with fetching streamer information using PHP and the Twitch API. My goal is to show stream details on my website. Right now I’m testing with hardcoded usernames, but later I plan to get these names from a MySQL database.
I want to display the streamer name and current viewer count for each channel. However, my current code isn’t working and returns no data. I’m not sure what’s going wrong.
Here’s something nobody’s mentioned yet - even after you fix the auth and move to Helix API, you’re gonna hit rate limits if you’re checking multiple streamers regularly. I found this out the hard way when I deployed without any caching. Twitch gives you 800 requests per minute with app tokens, which sounds like plenty but disappears fast when you’re polling constantly. Set up basic caching with file storage or memcache. Cache stream data for 30-60 seconds before making new API calls. Also batch your requests - Helix streams endpoint takes multiple user logins in one call (just comma-separate them). This cuts your API usage way down when checking several channels at once.
yeah, justin.tv’s dead - hasn’t worked in ages. your code’s not right either since you’re saving channel names not the actual stream data. twitch now needs oauth tokens with their helix api. you can’t just call the endpoints like before.
Quick heads up - watch out for the user_login vs user_id thing in Helix. Twitch’s API gets finicky with usernames that have special characters or numbers. Learned this the hard way when streamer names kept failing to resolve.
You’re hitting a dead API - Justin.tv was discontinued ages ago when Twitch took over. Plus there’s a bug in your PHP code. You’re only storing the channel name in $channelData, not the actual API response. Even if the old API still worked, you wouldn’t get any stream info this way.
I had the same headaches when I built my stream tracker. You need to switch to Twitch’s Helix API and set up OAuth. Get an app access token with your client credentials, then hit https://api.twitch.tv/helix/streams?user_login=username with proper auth headers.
The response format’s totally different now, so you’ll need to rewrite how you parse the JSON for viewer counts and stream status. Also, ditch file_get_contents for cURL - way better error handling and you can manage headers properly.
You’re using the old Justin.tv API that’s been dead for years. Twitch scrapped their whole API system and now requires proper auth with client credentials. First, register an app on the Twitch Developer Console to get your Client ID and Client Secret. Then switch to the new Helix API with OAuth2 authentication. You’ll need an access token before making any calls. I went through the same headache migrating from the old API. The new system’s more secure but needs extra setup. Use https://api.twitch.tv/helix/streams as your base endpoint and include proper headers with requests. The response structure changed too, so you’ll need to fix your JSON parsing. Without proper auth headers, you’ll just keep getting empty responses or errors.
You’re trying to use Justin.tv’s old API, which got completely shut down when Twitch bought them. Plus there’s a logic error in your code - you’re pushing the channel name into $channelData instead of the actual decoded response. Even with a working API, you wouldn’t get any stream data.
I ran into the same thing building my channel monitoring script last year. Twitch’s current API needs you to register through their developer portal first. You’ll need an app access token using your client ID and secret, then hit their Helix endpoints with the right Authorization and Client-ID headers.
For stream data, use https://api.twitch.tv/helix/streams with the user_login parameter. The JSON structure’s totally different now - viewer count is under viewer_count. Also add rate limiting since Twitch’s pretty strict about API quotas. Ditch file_get_contents for cURL so you can control headers and handle errors properly.
Beyond the outdated API, you’re not actually processing the response data. Your $channelData array only has channel names - no stream info. I made the same mistake when I started with Twitch integration. Switch to Helix API and get proper auth working first. Then check if the stream’s actually live before doing anything else. The streams endpoint returns empty arrays for offline channels, which catches tons of people off guard. Validate your response structure before grabbing viewer counts. Don’t forget error handling for timeouts and API failures - Twitch gets flaky during peak hours. Get the basics working, then test it hard with live and offline channels so you don’t get burned in production.