Getting twitch username during oAuth process

Hi,

I’m creating an app app which involves Twitch IRC. In order to do this I need a couple of bits of information:

  1. The oAuth token
  2. The twitch username of the user

I’ve successfully managed to obtain the oAuth token through the ‘implicit grant flow’ by extracting it from ‘document.location.hash’ in the url as outlined in the link:
(https://github.com/justintv/Twitch-API/blob/master/authentication.md#auth-code)

However this information does not include the username of the user which is required to connect to IRC. In order to connect I would need to ask the user to enter their username again into my app?

Is there any way to get the twitch username through the oAuth process?

Many thanks for your help

Once you have the oauth token it is a simple API call to get the username. A simple get request to the root api (https://api.twitch.tv/kraken) will return the username.

See: https://github.com/justintv/Twitch-API/blob/master/v2_resources/root.md

1 Like

Thanks so much! I had looked through the api files as I thought there must be something like that but must have missed it.

Cheers!