Skip to content

Instantly share code, notes, and snippets.

@spddl
Created April 23, 2021 14:42
Show Gist options
  • Save spddl/54be0e53f8fcf307af5a1a7a82f121c8 to your computer and use it in GitHub Desktop.
Save spddl/54be0e53f8fcf307af5a1a7a82f121c8 to your computer and use it in GitHub Desktop.

Benötigt wird die SteamElements "Channel ID" und der "JWT Token".

  • Denn JWT Token findet man Offiziell unter Channels und "Show secrets"
  • Die Channel ID sieht man in der Entwicklerkonsole (F12) wenn man z.b. auf "Leaderboard" klickt (Oben die Channel ID, unten nochmal der JWT Token)

image

Mit diesem beiden Keys kann man die Punkte der Viewer auslesen und verändern:

// hier ein NodeJS Beispiel
const fetch = require('node-fetch')
const token = '' // 361 Zeichen lang
function GetUserpointsForSpecificUsername(chan, user) { // https://docs.streamelements.com/reference/single-user#pointsbychannelanduserget
fetch('https://api.streamelements.com/kappa/v2/points/' + chan + '/' + user, { method: 'GET', headers: { Accept: 'application/json', Authorization: 'Bearer ' + token } })
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err))
// Response: {
// channel: '5f89f7f37573f5360e4bae13',
// username: 'spddl',
// points: 5,
// pointsAlltime: 150,
// watchtime: 0,
// rank: 1
// }
}
GetUserpointsForSpecificUsername('5f89f7f37573f5360e4bae13', 'spddl')
function UpdateAllTimePointsForUser(channel, user, amount) { // https://docs.streamelements.com/reference/single-user#pointsalltimeamountbychannelanduserput
fetch(`https://api.streamelements.com/kappa/v2/points/${channel}/alltime/${user}/${amount}`, {
method: 'PUT',
headers: { Accept: 'application/json', 'Content-Type': 'text/plain', Authorization: 'Bearer ' + token }
})
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err))
// Response(+100): {
// channel: '5f89f7f37573f5360e4bae13',
// username: 'spddl',
// amount: 100,
// newAmount: 200,
// message: 'Added 100 points to user spddl'
// }
// Response(-50): {
// channel: '5f89f7f37573f5360e4bae13',
// username: 'spddl',
// amount: -50,
// newAmount: 150,
// message: 'Removed -50 points to user spddl'
// }
}
UpdateAllTimePointsForUser('5f89f7f37573f5360e4bae13', 'spddl', 100)
UpdateAllTimePointsForUser('5f89f7f37573f5360e4bae13', 'spddl', -50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment