twitchdev / issues

Issue tracker for third party developers.
Apache License 2.0
73 stars 6 forks source link

Videos endpoint empty data array when specifying a game_id #651

Open Dkamps18 opened 2 years ago

Dkamps18 commented 2 years ago

Brief description Videos endpoint returns an empty data array when specifying a game_id and querying from a browser.

How to reproduce Call the videos api with a game_id from any browser.

Expected behavior Match the behavior of the endpoint when being called from outside a browser

Screenshots Not a screenshot but you can use this page as an example

Additional context or questions Only broken when querying from a browser

BarryCarlyon commented 1 year ago

I narrowed down the problem on this one.

Browser fetch (and by extension nodeJS inbuild fetch: aka Fetch that follows the spec), adds a accept-langauge header.

If that header is set to the value of * or anything valid, such as en-US for example, you get no results

But if you set the header to jibberish, then you get results

let url = 'https://api.twitch.tv/helix/videos?game_id=32399';

let r = await fetch(
    url,
    {
        method: 'GET',
        headers: {
            'Client-ID': `${client_id}`,
            'Authorization': `Bearer ${token}`,
            'Accept': 'application/json',
            'accept-language': 'YOUWHAT'
        }
    }
);
let p = await r.json();

console.log(p);