Is there a way to get streamer ID via the JavaScript Helper?

Can we grab the ID of the streamer (without any config or OAuth) in the viewer.html using the JavaScript Helper? This ID would then be used to grab data from other Twitch APIs e.g. followers (not PubSub).

You can get that from the Javascript Helper: onAuthorized event.

If I may I have a question too in the following post

window.Twitch.ext.onAuthorized(
    function(auth){
        var parts=auth.token.split(".");
        var payload=JSON.parse(window.atob(parts[1]));
        var streamer_id = payload.channel_id;
    }
);

Also:

var streamer_id = payload.opaque_user_id.replace('U', '');

A broadcaster’s token is set with “U” + his Twitch user ID, to avoid confusing his opaque ID with his user ID when he is a viewer.

Can also cross check that

payload.role == 'broadcaster'

To see if the ID’s below to the streamer that the extension is installed on

1 Like

@BarryCarlyon & @Alca thank you very much. I had seen “onAuthorized” in the docs, but had assumed that it was an event that fired after the streamer carried out an authorization handled via the EBS due to the docs stating it fired when the JWT was updated. I have tested and am able to get the data I was expecting so thank you very much for explaining!

Not sure if it was my poor understanding or unclear documentation that lead to the confusion, but thought I would explain my train of thought in case someone else has a similar case and comes across this thread.

Would I be right in saying I can also use a window.Twitch.ext.listen() to automatically receive Twitch’s own PubSub events (e.g. bit donation) without needing to auth the streamer in any way?

The docs say you can listen: https://dev.twitch.tv/docs/extensions/reference#javascript-helper

Non-extensions PubSub topics also are supported with this function; for example:
channel-bits-events-v1.

I have not tested it myself, the example event of “channel-bits-events-v1.” you are supposed to provide an oauth/scope according to the pubsub docs, but there’s no way to provide an oauth/scope under listen. So perhaps calls to listen in extensions bypass the need for the auth here, as the JWT/Twitch listener handles that.

But a given JWT/listen combo has a specific channelID in the decoded payload anyway.