Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
twitch-helix
Advanced tools
Readme
Little helper class for the new Twitch API described in current Twitch API docs.
Transpiled and minified with Babel.
Feel free to contribute by creating issues and pull requests.
Yarn (recommended)
yarn add twitch-helix
npm
npm install --save twitch-helix
Import the default class from this package and feed its constructor with a client ID and a client secret. You can generate those in your Twitch Developers Dashboard.
Try it out on RunKit!
import TwitchHelix from "twitch-helix"
// Or: const TwitchHelix = require("twitch-helix")
const twitchApi = new TwitchHelix({
clientId: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
clientSecret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
})
twitchApi.getTwitchUserByName("nightbot").then(twitchUser => {
console.log(twitchUser.display_name) // Prints "Nightbot"
})
TwitchHelix is a class and you need to create an instance with:
const twitchApi = new TwitchHelix(options)
The options parameter is an object and can have following fields:
Field | Info | Default value |
---|---|---|
clientId | Client ID of your Twitch app | :no_entry_sign: (required) |
clientSecret | Client secret of your Twitch app | :no_entry_sign: (required) |
prematureExpirationTime | Time in ms for the access token to expire before it is meant to (Not implemented yet) | 10000 |
autoAuthorize | Will call automatically call authorize() when needed | true |
smartRetry | Will retry Twitch API requests up to 10 times if the server response is invalid | true |
Some of the common queries are wrapped into neat functions. Those are:
Promise | Name | Parameters | Return Value | Further info |
---|---|---|---|---|
Yes | getTwitchUserById | string id | Twitch user info object | |
Yes | getTwitchUserByName | string username | Twitch user info object | |
Yes | getTwitchUsersByName | Array usernames | Array of Twitch user info objects | |
Yes | getStreamInfoById | string id | Twitch stream object if user is currently streaming or null otherwise | |
Yes | getStreamInfoByUsername | string username | Twitch stream object if user is currently streaming or null otherwise | |
Yes | getFollowDate | string streamerId , string followerId | Date if follower follows streamer or null otherwise |
You may need custom queries for retrieving data that is not wrapped into a function yet. Feel free to do so. Some API endpoints are still not implemented by Twitch in Helix API, so you can also use Kraken v5 API.
const helixQueryData = await twitchApi.sendHelixRequest("users?login=nightbot&login=moobot")
const krakenQueryData = await twitchApi.sendApiRequest("users?login=nightbot,moobot", {api: "kraken"})
You can listen to some events.
twitchApi.on(eventName, eventHandler)
Event name | Parameters | Description |
---|---|---|
log-info | message | Emitted on INFO log messages |
log-warn | message | Emitted on WARN log messages |
log-error | message | Emitted on ERROR log messages |
Here is an example:
node_modules/.bin/twitch-helix --client-id xxx --client-secret xxx "users?login=nightbot"
Use the --kraken
flag to query data from a Kraken endpoint instead of a Helix endpoint.
FAQs
Little helper class for the new Twitch Helix API
The npm package twitch-helix receives a total of 2 weekly downloads. As such, twitch-helix popularity was classified as not popular.
We found that twitch-helix demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.