Hello,
I have registered my application and generated OAuth token through Twitch CLI.
get channel information: url= ‘https://api.twitch.tv/helix/channels?broadcaster_id=132954738 ’ runs without error but when I try to get game analytics using url = ‘https://api.twitch.tv/helix/analytics/games?game_id=493057 ’ or editor details using url = 'https://api.twitch.tv/helix/channels/editors?’
I get the below error:
"error": "Unauthorized",
"status": 401,
"message": "incorrect user authorization"
how is the Token working for a few commands and not for all. Any help?
TIA,
SN
You appear to have create a client credentials
token, which generally is fine for calling public data endpoints.
To call the editors endpoint you need permission from the broadcaster, which is acheived by generating a User token
with the relevant scope attached.
As you need a token that represents a user, a client credentials
represents no one (well technically you clientID which isn’t a user)
As per
Authentication
OAuth user token required
Required scope: channel:read:editors
As for games, well you’ll need to be part of an organistation that owns a game!
Gets a URL that game developers can use to download analytics reports (CSV files) for their games.
Authentication
OAuth token required
Required scope: analytics:read:games
A user token is
Getting Tokens: OAuth
See also
Authentication
Thank you.
how do I “Send the user you want to authenticate to your registered redirect URI:”?
Redirect URL is http://localhost
Normally your oAuth flow will reside on a website
So the link to start the auth process is housed in an <a href="">Login with Twitch</a>
This is an example that implements implicit auth, which generates a token that is non refreshable, so generally not the token you need but will illistrate the flow
https://barrycarlyon.github.io/twitch_misc/authentication/implicit_auth/
The TwitchCLI will do this with the -u
flag as well
It’ll open the web browser from the command line to do the auth with
The guide:
# Token
Used to fetch an access token. This can fetch either an app access token or user token (with scopes) and stores for further use. It is important to note that this requires the running of `twitchdev configure` before it'll fetch tokens. If you don't run [`configure`](configure.md) prior to running `token`, you will be prompted to configure the application.
**IMPORTANT**
To use user tokens, you will need to set up your Client ID provided during [`configure`](configure.md) with a redirect URI of `http://localhost:3000`. App access tokens will work without this step. You can configure that [on the Twitch Developer console](https://dev.twitch.tv/console).
**Args**
None.
**Flags**
| Flag | Shorthand | Description | Example | Required? (Y/N) |
|----------------|-----------|-------------------------------------------------------------------------------------------------------|----------------------------------------------|-----------------|
| `--user-token` | `-u` | Whether to fetch a user token or not. Default is false. | `token -u` | N |
| `--scopes` | `-s` | The space separated scopes to use when getting a user token. | `-s "user:read:email user_read"` | N |
| `--revoke` | `-r` | Instead of generating a new token, revoke the one passed to this parameter. | `-r 0123456789abcdefghijABCDEFGHIJ` | N |
This file has been truncated. show original
thanks again. I did the below:
changed the redirect url for my app http://localhost:3000
twitch token -u -s “user:read:email”
Redirected to app for authorization >> authorized it
What next?
user ~ % twitch token -u -s "user:read:email"
Opening browser. Press Ctrl+C to cancel...
Where will I get the user token?
Did the browser page then go “you can close the window now”?
Or did it hang?
Worse case you ran into a twitch-cli weird so you can just go and build the proper oAuth flow instead of the TwitchCLI for testing.
The TwitchCLI generally doesn’t expose the token to you as it’s for use internally by the TwitchCLI for testing API endpoints with. But will will display the token when it does the code to token exchange.
You can also probably pull the token from the .env file for the rig, which on MacOS is in ~/.twitch-cli/.twitch-cli.env
I don’t know on windows.
But again, the CLI is for testing in the CLI not really for extracting the token for use elsewhere.
Yes, browser page showed " Feel free to close this browser window."
Did the console display an output similar to my screenshot?
No.
nshaloo@38f9d33e3fd7 ~ % twitch token -u
Opening browser. Press Ctrl+C to cancel…
Weird, time to skip the CLI and possibly report an issue
And build a proper oAuth flow instead.
The browser displays “Feel free to close this browser window.” but no user token generated.
no response on console.
system
closed
April 6, 2022, 12:55am
#13
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.