GithubHelp home page GithubHelp logo

wllew4 / node-ttv Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 52 KB

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

License: MIT License

JavaScript 1.20% TypeScript 98.80%
node-ttv node-wrapper oauth node nodejs node-js twitch twitch-api twitch-api-helix twitchtv twitch-tv web webrequest web-request

node-ttv's Introduction

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.

Not actively maintained, please open an issue if you need me to add any missing functionality.

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.

Generating authentication links:

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);

node-ttv's People

Contributors

janellewatwit avatar wllew4 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.