Getting user info and display them on a website

I want to create mini-games on my website and saving scores of the players with their Twitch username, I want the players to use their Twitch account to play,

I succeeded to use this Get Users Api Twitch and I can now see my own informations on my website but I had to hard-code my username as the login Optional Query Parameter,

How can I after redirecting the user to this link (link Twitch), get his username to put it instead of my hardcoded username ?

As the Get Users Endpoint states: “If neither a user ID nor a login name is specified, the user is looked up by Bearer token.”

If you omit both mentioned parameters, the token will be used as the source instead, giving you what you want :slight_smile:

Oh thanks, I was now looking at the “Validation requests” section of this page Authentication | Twitch Developers, it looks like it returns the username too ?

That it does - however, if you want the display_name, not the login, you’ll want the Get Users endpoint. Depends on your usecase!

Thank you very much man, you can close the topic !

1 Like

Here is a code example to demostrate the work flow using implict auth

@BarryCarlyon thank you


Thanks mate it’s very helpful for me,

  1. I want that the user datas to persist in my website to avoid the user to have to authorize the app via Twitch Popup everytime, I can use localStorage to store the accessToken and the expirationDate ?

  2. How do you do to avoid the user to click on “authorize app” ? It looks like the redirection is done automatically on your site ?

  3. I’m using React/Node and I was using to get the accessToken and then to get the username and id of the user, but it seems you directly do the request on helix/users you ?

You normally wouldn’t use client side, You’d use a server based session for this, but depends on the use case, And thus not use implict auth.

However, sure you can store the users own token in the users own localStorage.

This depends how you want to manage user website persistance. For my websites/minisites, I’ll use regular oAuth flows to get a server session and back that with my DB. but depends what I need to login people for.

The linked Implict Auth Example, is just an easy way to demonstrate how to get a user from a oAuth token.

You have to click “authorize app” to provide a token.

Without force_verify if you already linked, the flow just loops around without the “confirm” link. If thats what you mean.

This question is unclear

This example being implict auth.

  • The user clicks the auth link. -
  • That goes to twitch
  • They accept/decline (skipped if authed once and no forceverify)
  • They return to the webpage with a
  • My code grabs the #access_token from the URL
  • And then uses the access token in the calls to helix.

For implcit auth there is no ?code to access token exchange
As the access token is provided in the URL fragment

For an example of “Server based” sessionage see user_access_generator

Here you go

  • Twitch Link
  • That goes to twitch
  • They accept/decline (skipped if authed once and no forceverify)
  • They return to the webpage with a ?code query string argument
  • Your server exchanges the ?code for an access token
  • Use the access token as needed

There isn’t a “live” example of this as GitHub doesn’t have a “Server” to run server code/sessions with.

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