Embedding with Hosts or Community specific?

Hi there, I’m working on a streamer site and have a bit of PHP detecting whether a channel is online or not, from which if false, it will show the embedded player with who is being hosted, but as a bit of research has proven, this does not seem to be possible.

A possible workaround might be to allow embedding from an array of users streaming under a community? However I’m unsure how to execute this. Any help is greatly appreciated!

Hi,

From my understanding you want to get live users from a certain community, and embed their streams onto your site.
Here is something I threw together;
In this example I’ve used cURL however you may modify it to suit your needs.


What you wanna use is the Twitch V5 API, and use the /communties and the /streams endpoints.

First off, you need to get the community ID, to do this you need to make a call to the /communties/ endpoint and search by Community Name, this can be perfomed by doing the following cURL

curl -H 'Client-ID: {your_client_id}'  \
-H 'Accept: application/vnd.twitchtv.v5+json'  \
-X GET 'https://api.twitch.tv/kraken/communities?name={community_name}'

After performing this you will get a response similar to this,

{
    "_id": "8deb7b0f-d5a3-4f9d-942d-2331d8f4fe3d",
    "avatar_image_url": "",
    "cover_image_url": "",
    "name": "lgbt",
    ...
}

From the response, you get the community ID which is seen under the _id string.
In this example, the community used is the LGBT community, and the ID fetched is 8deb7b0f-d5a3-4f9d-942d-2331d8f4fe3d.

Now that we have retrieved the _id, we can perform a request against the /streams endpoint, to do this we perform the following cURL.

curl -H 'Client-ID: {your_client_id}'  \
-H 'Accept: application/vnd.twitchtv.v5+json'  \
-X GET 'https://api.twitch.tv/kraken/streams/?community_id={community_id}'

And will return something along the lines of this,

{
    "_total": 215,
    "streams": [
    {
    "_id": 28331609184,
    "average_fps": 60,
    "channel": {
        "_id": 38948800,
        "broadcaster_language": "en",
        "created_at": "2018-04-14T18:57:42Z",
        "display_name": "KneeColeslaw",
        "followers": 321338,
        "game": "Fortnite",
        "language": "en",
        "logo": "....",
        "mature": true,
        "name": "kneecoleslaw",
        "partner": true,
        "profile_banner": ".......",
        "profile_banner_background_color": null,
        "status": ".......",
        "updated_at": "2018-04-15T02:53:47.23503Z",
        "url": "https://www.twitch.tv/kneecoleslaw",
        "video_banner": "https://static-cdn.jtvnw.net/jtv_user_pictures/4d9a1c3ca065f1ee-channel_offline_image-1920x1080.png",
        "views": 24975845
  },
  ...
  ]
}

However it will return multiple streams, matching the community ID specified above (in this case the LGBT community).

Then from this, you can get the channel username(s) currently live under the community.


The above example shows how to get a list/array of users currently streaming under a community.

I hope this can somehow help, I apologize if this is poorly written however I just wrote this now. If you need clarification or for me to expand on any of this please let me know.

Drew.

1 Like

Not poorly written at all, absolutely perfect. I’m actually going to put together a quick tool for this and host it. Will reply here when its finished. :slight_smile:

Just to alleviate the workaround for gathering IDs a little more.

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