How to get the user id after authentication?

After making this request:

https://id.twitch.tv/oauth2/authorize
    ?client_id=<your client ID>
    &redirect_uri=<your registered redirect URI>
    &response_type=code
    &scope=<space-separated list of scopes>

How can I get the user id with new API?

Call the users API with just the oAuth token and no ID as a query string argument

For example, from the docs

curl -H 'Authorization: Bearer cfabdegwdoklmawdzdo98xt2fo512y' \
- H 'Client-ID: the_clientid_for_this_token` \
-X GET 'https://api.twitch.tv/helix/users

Will return the user associated with that Bearer token

Or the validate endpoint

1 Like

Hello, it returns:

{
    "error": "Unauthorized",
    "status": 401,
    "message": "Must provide a valid Client-ID or OAuth token"
}

With your example and applying it to my application

That would suggest your oAuth token is not a user Access token and has no User associated with it.

Additionally the token in my example is from the docs and invalid

IE: cfabdegwdoklmawdzdo98xt2fo512y is not a valid token

(Also the docs example hasn’t been updated to note the requirement of the ClientID to be present Requiring OAuth for Helix Twitch API Endpoints updated my reply above for the client-id inclusion )

Example and working code/demo using implicit auth at https://github.com/BarryCarlyon/twitch_misc/tree/master/authentication/implicit_auth

1 Like

Thanks for your help, now it works me.

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