You also need to own the game you are trying to collect analytics for, (ie your user account is a member of an organistation that owns the game you wish to collect analytics of)
oAuth works as follows
Step 1) user clicks a link to visit twitch
Step 2) user accepts or delcines access
Step 3) user returns to your redirect URI with a ?code
Step 4) Exchange the code for a token.
Your code above appears to be trying to fetch Step 1 instead of redirecting the user to Twitch