Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-ttv

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-ttv

A Node.js wrapper for Twitch.tv's helix API.

  • 2.1.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

node-ttv

npm npm bundle size License

A Node.js wrapper for Twitch.tv's API.

This package adds a useful abstraction layer to make it easier for developers to interact with the API.

Please note that versions 2.0.0 and later are NOT backwards compatible with earlier versions. There were significant structural overhauls made to this project. Node-ttv is much easier to use now, so depending on how deeply integrated this package is in your project, migrating may not be too difficult.

Getting Started

Register your app

In order to interact with Twitch's API, you must have a registered application with a client ID and secret. You can register a new application here.

Install node-ttv

Create a new project with either npm or yarn. Install the node-ttv package:

npm install node-ttv
or
yarn add node-ttv

Import node-ttv and create a handle to your application

const { Twitch } = require('node-ttv')

const myTwitchApplication = new Twitch(CLIENT_ID, SECRET);

Non-user-specific requests

Requests that do not require user authentication can be made with no further setup required. Endpoints are sorted by resource as specificed by Twitch.tv's API documentation. Refer to their documentation for information on endpoint behavior.

All endpoint functions return a Promise<string> which is a serialized JSON object. Make sure you treat the return value as a Promise<>, using .then() or await.

myTwitchApplication.helix.chat.getGlobalEmotes().then(console.log)

User-specific requests

Making requests on behalf of a user requires their authentication. Node-ttv can generate OAuth 2.0 links to send your users so they can authenticate your app with provided scopes. Read more about how authentication works here.

Your implementation is responsible for handling and storing user access tokens, as well as serving authentication links to users and retrieving access tokens from the redirect.

At this point in time there are no plans to implement support for OIDC tokens. As a result, the Extensions resource is not supported by node-ttv.

const { Twitch, OAuth, Scopes } = require('node-ttv')

const myTwitchApplication = new Twitch(CLIENT_ID, SECRET);

//	Implicit code flow
let sendThisToUser = OAuth.implicitUserAccessToken(CLIENT_ID, REDIRECT_URL, [Scopes.CHANNEL_READ_REDEMPTIONS]);
let orThis = myTwitchApplication.oauth.implicitUserAccessToken(REDIRECT_URL, [Scopes.CHANNEL_READ_REDEMPTIONS]);

//	Authorization code flow
let sendThisToUser = OAuth.authorizationUserAccessToken(CLIENT_ID, REDIRECT_URL, [Scopes.CHANNEL_READ_REDEMPTIONS]);
let orThis = myTwitchApplication.oauth.authorizationUserAccessToken(REDIRECT_URL, [Scopes.CHANNEL_READ_REDEMPTIONS]);

Making authenticated requests:

In this example, USER_ACCESS_TOKEN has been generated with Scopes.CHANNEL_EDIT_COMMERCIAL and '123456789' is their broadcaster_id.

myTwitchApplication.ads.startCommercial(USER_ACCESS_TOKEN, '123456789', 30);

License

Node-ttv is licensed under the MIT permissive license. You may use this package in your projects freely, and no warranty is provided. Read the provided LICENSE file for the complete license text.

Keywords

FAQs

Package last updated on 14 Jun 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc