Two questions about TwitchExtention

I have two questions about Extension.

  • I would like to ask about best practices for displaying only to users specified in EBS in TwitchExtensions.

  • I would like to know how to get the HelixToken when calling the TwitchAPI (GetUser) on the Extensions.
    I tried to get the Token, but the HelixToken is undefined and cannot be obtained.

Could you answer the question?

What code did you try.

The HelixToken is returned in the onAuthorised callback. So you would extract it from the variable passed to the callback

Here is an example


let helix = {};
window.Twitch.ext.onAuthorized((auth) => {
    helix = {
        'Client-ID': auth.clientId,
        'Authorization': 'Extension ' + auth.helixToken
    }
});

function collectHelix() {
    if (!window.Twitch.ext.viewer.isLinked) {
        return;
    }
    fetch(
        'https://api.twitch.tv/helix/users/?id=' + window.Twitch.ext.viewer.id,
        {
            method: 'GET',
            headers: helix,
        }
    )
    .then(resp => {
        return resp.json();
    })
    .then(resp => {
        var table = document.createElement('table');
        document.getElementById('helix_log').append(table);
        for (var key in resp.data[0]) {
            var tr = document.createElement('tr');
            table.append(tr);
            var td = document.createElement('td');
            td.textContent = key;
            tr.append(td);
            var td = document.createElement('td');
            td.textContent = resp.data[0][key];
            tr.append(td);
        }
    })
    .catch(err => {
        console.log(err);
    });
}

Not 100% sure what you are intending.

Sounds like you wish to use AllowListing but EBS enforced rather than the Twitch list

Thanks for the reply.

Do I need to do some additional configuration somewhere else?
The code for HelixToken looks like this.
I am able to get the Token and UserId values.

window.Twitch.ext.onAuthorized((auth) => {
console.log(‘token’ + auth.token);
console.log(‘userId’ + auth.userId);
console.log(‘helixToken’ + auth.helixToken);
});

Not 100% sure what you are intending.

Sounds like you wish to use AllowListing but EBS enforced rather than the Twitch list

Yes, it is.
For example, I would like to know the best practices when I have processed multiple users in EBS and want to show OK for only certain users and NG for others.

Use one method or the other method, their is no best practice for this yet

Not sure what you are asking here, is it working or not working?

My test extension shows it’s working fine/as expected.

This test code obtained the helix token and made a call to helix for the channel data

I apologize for the delay in responding.

Use one method or the other method, their is no best practice for this yet

Does this mean that there is not yet a function to display only to specific users?

Not sure what you are asking here, is it working or not working?
My test extension shows it’s working fine/as expected.

I did not post the code as is, but modified it.
I will try to rebuild this one from scratch again.

If you want to send a message to a specific user, use the whisper pubsub topic or the “regular” pubsub topic with a user_id in the message.

Then your frontend can interpret the inbound message.

Whispers are only for that user
Regular pubsub (channel or broadcaster) you can compare the user_id in the message with the user_id the extension has.

Do what works best for you and your extension.
I tend to avoid the whisper topic due to the rate limit implications.
So I’ll use the global topic with many messages and many user_id’s to handle rate limit
So depends on the quantity of messages you need to send.

I also on some extensions don’t use pubsub and run a custom system to do exactly what I need.

So best practice wise: choose whats best for your needs and message send counts.

Thank you.
I think I will try PubSub first.

Regarding HelixToken, the cause is probably the same.
I am also using TwitchDeveloperRig.