Broadcaster_id field in the api

Im trying to call https://api.twitch.tv/helix/channels/commercial and in the raw data it requires a broadcaster_id. What is it and how do I find it? The id I get from get users api call also doesn’t work.

1 Like

The ID you need is from the Get users API yes

So to run adverts on barrycarlyon
I’ll call Get Users to convert barrycarlyon to 15185913
Then I’ll use 15185913 on commerical endpoint to run the ads on my channel

A broadcaster_id is a user_id, different labels for the field are used to help describe entities involed in a give API call

Ok I got the id but now after calling the endpoint im getting a 401 Unauthorized error with the message: “The ID in broadcaster_id must match the user ID found in the request’s OAuth token.”. Headers are all ok.

To run adverts on 15185913 the oAuth token needs to have been created by 15185913

This error says you oAuth token belongs to bob but you are trying to run ads on freds channel.

I am using the id of my dev account in which I created the developer application. Could it be because of scope issues or something related? I’m fetching the access token through https://id.twitch.tv/oauth2/token with post field grant_type=client_credentials(along with client id and secret).

A client credentails token cannot be used on this endpoint

The owner of the ClientID is irrelevant

You seem to have not requested a user oAuth token from the user you want to run ads for

Normally a code grant flow is used for this use case

Yes that seems to be the problem, I’m using client app access token on user access token only endpoint. Since I’m writing this in C++ I don’t have a frontend in which to ask the user to authorize it, is there a way to get a user access token through HTTP requests or does it have to be a website?

oAuth user tokens requires the user to open a webpage to grant/allow access.

That could be
your script runs
Presents a URL
The user copies the URL to a browser
The user accepts (or declines) the access
Then copies the resultant code (or access token) back to your script

Example: https://github.com/BarryCarlyon/twitch_misc/tree/main/authentication/user_access_without_server

This NodeJS example will

This is similar to how the Google NodeJS API's examples work.

You start a script, it shows a URL to open.
You Google oAuth
A code is displayed
User/You copy and paste the code back into the interactive script
Away we go

Thank you for the tips ! :smiley:

Just had the time to implement it and it worked. Thanks for all the help and the example.

1 Like

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