Unable to Retrieve OAuth Client Credentials Token (Invalid ClientID)

I’m trying to develop an application that can get notifications when someone follows or subscribes to a channel. However, I cannot seem to get the client credentials access token needed to subscribe to the events.

Simply making the request in the command line like this:

curl -d client_id=$CLIENT_ID
-d client_secret=$CLIENT_SECRET
-d grant_type=client_credentials
https://id.twitch.tv/oauth2/token

with CLIENT_ID and CLIENT_SECRET being the keys I generated when I registered my app at https://dev.twitch.tv/console stored as environment variables

Always returns:

{“status”:400,“message”:“invalid client”}

I have read that this means that the client ID isn’t valid, however, even making a new application and generating new codes yields the same results. Manually entering the codes instead of using environment variables also yields the same result. I am 100% certain I have been entering the client ID properly.

Is there anything else I am doing wrong? Getting the OAuth token for users (for making chatbots) seems to work fine, but app tokens are not working for me.

Invalid Client is usually due to a bad request, not a bad client id.

In this case, make sure you’re following the Client Credentials OAuth flow as documented Getting Tokens: OAuth | Twitch Developers, which should be done from your server and not from a browser.

Additionally, as subscriptions is private data you’ll also need to use either the Implicit or Auth Code OAuth flows with the user you wish to get notifications for so that they grant your app that permission, otherwise when you try to use the App token to subscribe to EventSub for notifications it will deny you the ability to listen for subscriptions.

You omitted a -X POST so you made a GET request instead of a POST request.

So

curl -X POST https://id.twitch.tv/oauth2/token?client_id=MYCID&client_secret=MYSECRET&grant_type=client_credentials

So no need to pass as -d variables here really

So that’ll fix you for getting a Client Credentials token but as dist notes, this doesn’t work for subscriptions data, unless your ClientID is an Extension and the streamer has that extension installed with Subscription Permissions enabled

The endpoint docs:

Notes the authentication requirements

-X Post yields the same result as well, unfortunately.

Also, the documentation you linked says that data “Gets a list of users that subscribe to the specified broadcaster.” which is not what I want, but rather, simply a notification of when a channel gets a new subscriber with the notification type “channel.subscribe” which is similar to “channel.follow”. Could I not get that notification information with the broadcaster’s user access token (since it states " Must have channel:read:subscriptions scope."?) (Also, the app is an offline standalone application, with a place for the user/broadcaster to enter in credentials manually rather than going through the app extension page).

channel.subscribe is for eventsub

Which works as follows:

  1. Create a user oAuth flow that gets a user token for the channel with the relevant scope channel:read:subscriptions
  2. Discard the generated oAuth token (or keep it for spot checks)
  3. Create an app access token
  4. use the App access token with eventsub to create a subscription.

Also I’m using the Windows 10 version of cURL that comes with the newer builds of windows. I don’t know if the command options are different from Linux or Mac with this version.

That’ll be the issue, since curl in powershell actually ins’t curl it’s Invoke-WebRequest

So you’ll have to translate between the two. or just skip curl and move to code.

Yeah I’m trying to use Eventsub, and I’m stuck at the app access token bit. Should I not use Eventsub for notifications?

Sure you can I outlined the required steps above.

First you create a permission link between your clientID and the streamer for whatever scopes/permissions you need,
Then you use an App Access Token to generate the EventSub Subscriptions.
Keep the user token on file if you need to catch up.

EventSub is a “dual token” scenario.

But as to your OP

I would consume subscriptions (and resubs and primes) from chat.
And follows from EventSub.

Oh fun, that’s not annoying lol. Okay, I’ll see if I can’t find the correct translations or maybe find one of the older third-party alternatives that was used before that update.

So In powershell,

curl -Method POST "https://id.twitch.tv/oauth2/token?client_id=MYCID&client_secret=MYSECRET&grant_type=client_credentials"

or

Invoke-WebRequest -Method POST "https://id.twitch.tv/oauth2/token?client_id=MYCID&client_secret=MYSECRET&grant_type=client_credentials"

Should yield a token

Or jsut install curl instead!

I would consume subscriptions (and resubs and primes) from chat.
And follows from EventSub.

Wait you can get subscriptions from the IRC api? I didn’t see anything about that when I was making chatbots. Is the chat notified somehow when a sub occurs?

Cause that would be ideal to not have to bother the user with generating a user token.

Yes

USERNOTICE

Well you’d still need a user token for your chat bot (probably)

Oh yeah, I forgot about that, though that’d still be nicer than having to juggle two webhooks.

And yeah I see, that’s pretty cool you can send notifications to viewers, and since the bot is a viewer technically, it’s kind of a nice workaround. I have a chatbot set up in my app (it’s a throwaway account with the Oauth token hardcoded in), so this might workout a bit cleaner.

Thanks and hopefully I can get this token cleanly.

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