Socket
Socket
Sign inDemoInstall

twitch-helix

Package Overview
Dependencies
7
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    twitch-helix

Little helper class for the new Twitch Helix API


Version published
Weekly downloads
2
Maintainers
1
Install size
9.80 MB
Created
Weekly downloads
 

Readme

Source

twitch-helix

Little helper class for the new Twitch API described in current Twitch API docs.
Transpiled and minified with Babel.

npm Stats

Travis Build Status Dependency Status MIT License

Feel free to contribute by creating issues and pull requests.

Installation

Yarn (recommended)

yarn add twitch-helix

npm

npm install --save twitch-helix

Library Usage

Example

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"
})
Construction

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:

FieldInfoDefault value
clientIdClient ID of your Twitch app:no_entry_sign: (required)
clientSecretClient secret of your Twitch app:no_entry_sign: (required)
prematureExpirationTimeTime in ms for the access token to expire before it is meant to (Not implemented yet)10000
autoAuthorizeWill call automatically call authorize() when neededtrue
smartRetryWill retry Twitch API requests up to 10 times if the server response is invalidtrue
Implemented queries

Some of the common queries are wrapped into neat functions. Those are:

PromiseNameParametersReturn ValueFurther info
YesgetTwitchUserByIdstring idTwitch user info object
YesgetTwitchUserByNamestring usernameTwitch user info object
YesgetTwitchUsersByNameArray usernamesArray of Twitch user info objects
YesgetStreamInfoByIdstring idTwitch stream object if user is currently streaming or null otherwise
YesgetStreamInfoByUsernamestring usernameTwitch stream object if user is currently streaming or null otherwise
YesgetFollowDatestring streamerId, string followerIdDate if follower follows streamer or null otherwise
Custom queries

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"})
Events

You can listen to some events.

twitchApi.on(eventName, eventHandler)
Event nameParametersDescription
log-infomessageEmitted on INFO log messages
log-warnmessageEmitted on WARN log messages
log-errormessageEmitted on ERROR log messages

Command Line Usage

Here is an example:

node_modules/.bin/twitch-helix --client-id xxx --client-secret xxx "users?login=nightbot"

This will print: Command Line Output

Use the --kraken flag to query data from a Kraken endpoint instead of a Helix endpoint.

FAQs

Last updated on 30 Dec 2017

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc