Trying to use php to find if a channel is live

Your code doesn’t generate a token at all.

For this sort of application an App Access Token is appropriate

You should generate, store, and reuse the token (until it expires) and use that Token with your code, it’s a Simple curl POST request before you do touy Streams call.

Example that will do this, and store the token in a json file in the same directory https://github.com/BarryCarlyon/twitch_misc/blob/master/authentication/app_access_tokens/php/generate_and_maintain_token.php