Chatbot, Oauth2, curl requests?

Example, how to get some live streams

Docs

cURL example

curl -H 'Client-ID: uo6dggojyb8d6soh92zknwmi5ej1q2' \
-X GET 'https://api.twitch.tv/helix/streams?first=20'

NodeJS example using got

const got = require('got');

got({
    url: 'https://api.twitch.tv/helix/streams?first=20',
    method: 'GET',
    headers: {
        'Client-ID': 'uo6dggojyb8d6soh92zknwmi5ej1q2'
    },
    responseType: 'json'
})
.then(resp => {
    if (resp.data && resp.data.length > 0) {
        for (var x=0;x<res.data.length;x++) {
            console.log(res.data[x].user_name, 'is live', res.data[x].title);
        }
    } else {
        console.log('No Streams');
    }
})
.catch(err => {
    console.log(err, err.response.body);
});

Theress nothing to it, each documentation item, tells you the URL to call, the METHOD to use, any optional query strings, and JSON body stuff (for updating things).

So no really sure what you are after for a guide to follow, to convert documentation into code?!

1 Like