A quick question about the Embed API

Hello guys and girls :slight_smile: I would like to know if it is possible in the twitch embed option replace the channel name by a variable if so how I can proceed

Have fun

Yes

Just call setChannel as documented

Or just pass it in to the init function as documented

That dont work

Works fine in the code I’ve been using.

Define “dont work”

I want to create a system or it displays a random streamer each reload of the page but it does not work

Here is a JS Only example

<html>
<body>
  <!-- Add a placeholder for the Twitch embed -->
  <div id="twitch-embed"></div>

  <!-- Load the Twitch embed script -->
  <script src="https://embed.twitch.tv/embed/v1.js"></script>

  <!-- Create a Twitch.Embed object that will render within the "twitch-embed" root element. -->
  <script type="text/javascript">
    let channels = ['a','b','c','d'];
    let channel = channels[Math.floor(Math.random()*channels.length)];
    new Twitch.Embed("twitch-embed", {
      width: 854,
      height: 480,
      channel: channel
    });
  </script>
</body>

Yes but that return objectObject in twitch embed

Code didn’t format right edited

For example

Oh ok thanks you that work fine ^^ Thanks again

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