Twitch Extension

I was reading the documentation here Extensions | Twitch Developers and it mentions that the method Twitch.ext.onAuthorized will return a userId starting with U- in case the user is logged and with A- when it’s not.

However, when testing using the Twitch Developer Rig this is not the case. Is this some exception and when on production this will actually work?

Also, going from here, once I get the information that comes back from onAuthorized how do I go from here, to actually getting the viewer username and if possible the avatar.

Thanks in advance.

On a side note I guess the userId starts with U and not U- from what I have noticed.

But still not sure how to go from there to real username and avatar.

The OpaqueID is what starts with U/A. Only the broadcasters will become the users ID except for Bug or Intender: OpaqueUserId is _not_ UuserID when the broadcaster + extension uses ID Linking · Issue #559 · twitchdev/issues · GitHub use case

The opaqueID is more like a “sessionID”

To get the users true userID you need to request userID sharing and then get the userID when the user has logged in/shared their ID to the extension

Not sure without being in front of your rig to check all your settings.

if it’s

  • a rig issue,
  • a user view setup issue
  • a github 559 issue

After userID sharing:

Either use helixToken and call the API (not available in the rig or mobile) - No `helixToken` in the rig · Issue #471 · twitchdev/issues · GitHub or `helixToken` `undefined` in mobile apps · Issue #455 · twitchdev/issues · GitHub

Example: https://github.com/BarryCarlyon/twitch_extension_debug/blob/main/extension/panel/helix.js#L48

Or pass the JWT to an EBS - example: GitHub - BarryCarlyon/twitch_profile_extension: A simple Twitch Extension to cover the basics of using the JWT and EBS together to get Twitch API information

Don’t use the opaqueID, the opaqueID is essentially a sessionID and shouldn’t really be used for operations (other than the Extension PubSub whisper topic or storing “game progress” before a user logs in to the extension, like level 1/2 is free then you need to login)

ChannelID - is in onAuthorised - https://github.com/BarryCarlyon/twitch_extension_debug/blob/bec2c002cc930c9bfcb63c2dbc82e753eb54dcd1/extension/panel/script.js#L67
UserID - also in onAuthored but also in window.Twitch.ext.viewer.id is the viewer has authenticated/logged into the extension.

window.Twitch.ext.viewer.opaqueId - sessionID

window.Twitch.ext.viewer.id - logged in/id shared true userID
window.Twitch.ext.onAuthorized(auth => { channel_id = auth.channelId; } - channelId

Take the ID from the correct place for the user you want to get username/avatar.

Then either call the API locally, if on a platform that has helixToken
Or pass the whole JWT to an EBS and the EBS calls the API with an App Access Token.

1 Like