# General API question

**URL:** <https://discuss.dev.twitch.com/t/general-api-question/30479>\
**Category:** API\
**Created:** [February 16, 2021, 12:44pm UTC](https://discuss.dev.twitch.com/t/general-api-question/30479 "2021-02-16T12:44:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![SekiArt](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sekiart/32/11463_2.png) [@SekiArt](https://discuss.dev.twitch.com/u/SekiArt)\
**Post date:** [February 16, 2021, 12:44pm UTC](https://discuss.dev.twitch.com/t/general-api-question/30479/1 "2021-02-16T12:44:01Z")

</div>

Hey guys, first of all: I am trying my best with coding but stuff won’t work.

I am working on a streaming website, kinda creating a small streaming community.  
I got so far to embed the livestreams/streams to the website and now I am stuck with the VOD:

I kinda looked into the live code of the twitch site and I guess that there is no way around using the API to get the last X VOD. In my mind i would like to have the last 3 VOD in a row and some sort of description.  
Simple example:

**Description | VOD1 | VOD2 | VOD3**

Now the million dollar question:  
Can I grab the latest vod’s _WITHOUT_ using the API and get a code into my html/css/js?

For example: I used following code to show the preview you get when you are looking for a streamer; it shows in intervalls (dont know exactly which ones) the video that is been streamed (does not work on offline streams) but it is a fun little gimmick:

div\>  
div data-a-target=“search-result-live-channel” class=“search-result-card tw-flex”\>  
a class=“tw-link tw-link–inherit” href=“[https://www.twitch.tv/USERNAME](https://www.twitch.tv/USERNAME)”\>  
div class=“search-result-card\_\_img-wrapper tw-overflow-hidden tw-relative”\>  
img class=“search-result-card\_\_img tw-image” src=“[https://static-cdn.jtvnw.net/previews-ttv/live\_user\_USERNAME-214x120.jpg](https://static-cdn.jtvnw.net/previews-ttv/live_user_USERNAME-214x120.jpg)”\>  
/div\>  
/a\>  
/div\>  
/div\>

Is there a possibility to use such thing without the API for the latest 2,3 or 4 (X) VOD’S

---

<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:** [February 16, 2021, 12:46pm UTC](https://discuss.dev.twitch.com/t/general-api-question/30479/2 "2021-02-16T12:46:04Z")

</div>

> [@SekiArt](#):
>
> Can I grab the latest vod’s _WITHOUT_ using the API and get a code into my html/css/js?

How do you grab the latest vod’s without calling the API which is the only source for VOD’s? No idea.

> [@SekiArt](#):
>
> In my mind i would like to have the last 3 VOD in a row and some sort of description.

To do what you describe your backend would call the Video’s API and cache the ID’s periodicially (via a Cron job using an app access token).

Then your front end will fetch those cached video ID’s

---

<div class="post-metadata">

**Author:** ![SekiArt](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sekiart/32/11463_2.png) [@SekiArt](https://discuss.dev.twitch.com/u/SekiArt)\
**Post date:** [February 16, 2021, 12:51pm UTC](https://discuss.dev.twitch.com/t/general-api-question/30479/3 "2021-02-16T12:51:34Z")

</div>

So basically there is no work around around the api?  
Checking the Sourcecode of the VOD section of my stream it gives the video an ID, and I guess that that ID is being called from the database through the API, am I right with that?  
(I am seriously a noob and I feel uncomfortable)

---

<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:** [February 16, 2021, 12:54pm UTC](https://discuss.dev.twitch.com/t/general-api-question/30479/4 "2021-02-16T12:54:22Z")

</div>

> [@SekiArt](#):
>
> So basically there is no work around around the api?

Without calling the API where do you get the video ID’s from?

> [@SekiArt](#):
>
> Checking the Sourcecode of the VOD section of my stream it gives the video an ID, and I guess that that ID is being called from the database through the API, am I right with that?

Basically yeah, the API will lookup videos on Twitch’s database filtering by the search parameters you feed in (broadcasterID, video type etc) and return them

Generate one of these, an “App Access Token”

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

Then call

> **[Reference](https://dev.twitch.tv/docs/api/reference/)**
>
> Twitch Developer tools and services to integrate Twitch into your development or create interactive experience on twitch.tv.

Something like

```
https://api.twitch.tv/helix/videos?user_id=123&first=3&sort=time&type=archive

```

That’ll grab the last three VOD’s for user\_id/broadcaster 123

---

<div class="post-metadata">

**Author:** ![SekiArt](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sekiart/32/11463_2.png) [@SekiArt](https://discuss.dev.twitch.com/u/SekiArt)\
**Post date:** [February 16, 2021, 1:24pm UTC](https://discuss.dev.twitch.com/t/general-api-question/30479/5 "2021-02-16T13:24:12Z")

</div>

I understand a little bit more now, thank you a lot Barry \<3  
The OAuth token is no problem, I also understand the code snippet you provide.

What would now be the most elegant solution to implement it into JS and HTML?

---

<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:** [February 16, 2021, 1:25pm UTC](https://discuss.dev.twitch.com/t/general-api-question/30479/6 "2021-02-16T13:25:34Z")

</div>

> [@SekiArt](#):
>
> What would now be the most elegant solution to implement it into JS and HTML?

Well your front end needs to get fetch the video ID’s from the backend and just invoke after loading those ID’s. Whether you do that via server side rendering or post load fetch request via an API style endpoint you provide is up to you

---

<div class="post-metadata">

**Author:** ![SekiArt](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sekiart/32/11463_2.png) [@SekiArt](https://discuss.dev.twitch.com/u/SekiArt)\
**Post date:** [February 17, 2021, 8:58am UTC](https://discuss.dev.twitch.com/t/general-api-question/30479/7 "2021-02-17T08:58:54Z")

</div>

Since I am very bad at coding I fired up google and found the following;

> <https://stackoverflow.com/questions/61647395/how-to-add-oauth-token-in-js-for-twitch-api>

I followed the steps but could not make it work and I wonder what I did wrong

---

<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:** [February 17, 2021, 12:57pm UTC](https://discuss.dev.twitch.com/t/general-api-question/30479/8 "2021-02-17T12:57:13Z")

</div>

Well what error(s) did you get?  
What isn’t working?

---

<div class="post-metadata">

**Author:** ![SekiArt](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sekiart/32/11463_2.png) [@SekiArt](https://discuss.dev.twitch.com/u/SekiArt)\
**Post date:** [February 17, 2021, 1:03pm UTC](https://discuss.dev.twitch.com/t/general-api-question/30479/9 "2021-02-17T13:03:04Z")

</div>

nothing shows up basically. I know the workaround with the OAuth token is not the most elegant but just literally nothing shows up on the website.

Edit:  
I went to dev.twitch and created a new app, gave it a name etc and copied the Client ID and the Secret (I assume the Bearer Token) into the script

---

<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:** [February 17, 2021, 1:06pm UTC](https://discuss.dev.twitch.com/t/general-api-question/30479/10 "2021-02-17T13:06:31Z")

</div>

What you have linked to doesn’t cover token generation, and describes using tokens in the front end, (which generally speaking you shouldn’t use unless it’s the website users own token)

This is the documentation for server side token generation

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

Provides three different language examples on generating a server side token.

> <https://github.com/BarryCarlyon/twitch_misc/tree/main/authentication/app_access_tokens>
>
> //github.com/BarryCarlyon/twitch\_misc/tree/main/authentication/app\_access\_tokens

> [@SekiArt](#):
>
> I went to dev.twitch and created a new app, gave it a name etc and copied the Client ID and the Secret (I assume the Bearer Token) into the script

A Client Secret _IS NOT A BEARER TOKEN_

---

<div class="post-metadata">

**Author:** ![SekiArt](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sekiart/32/11463_2.png) [@SekiArt](https://discuss.dev.twitch.com/u/SekiArt)\
**Post date:** [February 17, 2021, 1:10pm UTC](https://discuss.dev.twitch.com/t/general-api-question/30479/11 "2021-02-17T13:10:05Z")

</div>

I understand and don’t understand. This is way to complicated for me and I thank you for your effort and time. \<3

---

<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:** [February 17, 2021, 1:13pm UTC](https://discuss.dev.twitch.com/t/general-api-question/30479/12 "2021-02-17T13:13:12Z")

</div>

1. Your Front end calls your backend
2. Backend loads/generates an app access token  
3 .Backend uses the token to get the last 3 VODs
3. Backend returns those videoID’s
4. Front end draws

You just need to sovle step 2. But the only guide you found is for front end Javascript, when you need to be using backend programming

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [April 9, 2021, 9:43am UTC](https://discuss.dev.twitch.com/t/general-api-question/30479/14 "2021-04-09T09:43:55Z")

</div>

Closed on April 9, 2021, 9:43am UTC

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