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

**URL:** <https://discuss.dev.twitch.com/t/is-there-a-way-to-get-streamer-id-via-the-javascript-helper/11935>\
**Category:** Extensions\
**Created:** [September 12, 2017, 11:35am UTC](https://discuss.dev.twitch.com/t/is-there-a-way-to-get-streamer-id-via-the-javascript-helper/11935 "2017-09-12T11:35:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tf2casperr](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/tf2casperr/32/9301_2.png) [@tf2casperr](https://discuss.dev.twitch.com/u/tf2casperr)\
**Post date:** [September 12, 2017, 11:35am UTC](https://discuss.dev.twitch.com/t/is-there-a-way-to-get-streamer-id-via-the-javascript-helper/11935/1 "2017-09-12T11:35:14Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Alca](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/alca/32/2783_2.png) [@Alca](https://discuss.dev.twitch.com/u/Alca)\
**Post date:** [September 12, 2017, 11:48am UTC](https://discuss.dev.twitch.com/t/is-there-a-way-to-get-streamer-id-via-the-javascript-helper/11935/2 "2017-09-12T11:48:48Z")

</div>

You can get that from the Javascript Helper: [onAuthorized event](https://dev.twitch.tv/docs/extensions/reference#onauthorized-functionauthcallback).

---

<div class="post-metadata">

**Author:** ![FrenchBarbu](https://avatars.discourse-cdn.com/v4/letter/f/7ab992/32.png) [@FrenchBarbu](https://discuss.dev.twitch.com/u/FrenchBarbu)\
**Post date:** [September 12, 2017, 12:07pm UTC](https://discuss.dev.twitch.com/t/is-there-a-way-to-get-streamer-id-via-the-javascript-helper/11935/3 "2017-09-12T12:07:29Z")

</div>

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

> [@User ID -\> Username Retrieval](https://discuss.dev.twitch.com/t/user-id-username-retrieval/11905/4):
>
> Hi, Im trying to figure out how to get the “real” userId. I do have granted the permission to see the user ID but the userId i get back from onAuthorized is UXXXXXXXXXXXX where X is not numeric (not a valid twitch id then) . What am I missing ?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [September 12, 2017, 12:23pm UTC](https://discuss.dev.twitch.com/t/is-there-a-way-to-get-streamer-id-via-the-javascript-helper/11935/4 "2017-09-12T12:23:45Z")

</div>

```
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

---

<div class="post-metadata">

**Author:** ![tf2casperr](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/tf2casperr/32/9301_2.png) [@tf2casperr](https://discuss.dev.twitch.com/u/tf2casperr)\
**Post date:** [September 12, 2017, 1:59pm UTC](https://discuss.dev.twitch.com/t/is-there-a-way-to-get-streamer-id-via-the-javascript-helper/11935/5 "2017-09-12T13:59:54Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [September 12, 2017, 2:08pm UTC](https://discuss.dev.twitch.com/t/is-there-a-way-to-get-streamer-id-via-the-javascript-helper/11935/6 "2017-09-12T14:08:40Z")

</div>

> [@tf2casperr](#):
>
> 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: [Extensions Reference | Twitch Developers](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.
