I can't access the parameters of the request

Hi, I tried everything on my side to try to get the data that Twitch sends me but I can’t.
The data is in the URL, I can see it on my browser but it’s before a # instead of ?
Here is an example :

here’s what my application tries to find information :
here’s what it finds :
But when I manually changes the URL to : http://localhost:8080/twitch?access_token=XXXXXXXXXXXXXXXXXXXX&scope=channel%3Amanage%3Apolls+channel%3Aread%3Apolls&token_type=bearer

It can find the data that Twitch sends :

Can anyone help ?

You are doing implict auth.

This will return a token that is in the #fragment fragments cannot be accessed by server side code.

Some javascript on the client will provide access:

For example: Twitch Implicit Auth Example - snippet:

        if (document.location.hash && document.location.hash != '') {
            var parsedHash = new URLSearchParams(window.location.hash.slice(1));
            if (parsedHash.get('access_token')) {
                var access_token = parsedHash.get('access_token');

It sounds like you may be using the wrong token flow if you need to get the token into a server side script. You may need to be using the code flow to generate a code you exchange for a token.

Or you need to use some javascript, as above, to extract the token and then push that to your server, but the code flow is preferred.


You are using implicit for getting a token, so need to extract the token using JavaScript - Getting OAuth Access Tokens | Twitch Developers

But I’m not sure if you need to be using code flow instead - Getting OAuth Access Tokens | Twitch Developers as it’s unclear from your use case as described

1 Like

I love you, you can’t imagine how much time i wasted trying to diagnose it thinking it must be an error in my application.
I switch to code and it’s the correct flow for my use case.

Thanks again !

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.