Class

TwitchTv

TwitchTv(options)

Constructor

new TwitchTv(options)

This module manages requests to the twitch api in a asynchonos manner
Parameters:
Name Type Attributes Description
options Object Options for the TwitchTv object
clientid String <optional>
The client id of the twitch api app
redirecturi String <optional>
The redirect uri of the twitch api app
scope Array <optional>
An array of the permission scopes you might need

View Source lib/twitchtv.js, line 6

Members

String

channelid

The channel id of the logged in user. Until now it's the same as the user id but it might change.

View Source lib/twitchtv.js, line 53

null | Object

channelobj

An object with all twitch channel information. More information in the twitch api documentation.

View Source lib/twitchtv.js, line 58

String

clientid

The twitch api app client id that is necessary for request to the twitch api.

View Source lib/twitchtv.js, line 22

String

redirecturi

The redirect uri that ist set in the app settings.

View Source lib/twitchtv.js, line 27

Array

scope

An array with the required permission scopes.

View Source lib/twitchtv.js, line 32

String

userid

User id of the logged in user.

View Source lib/twitchtv.js, line 43

null | Object

userobj

An object with all twitch user information. More information in the twitch api documentation.

View Source lib/twitchtv.js, line 48

Methods

getAuthImplicitGrantFlowUrl() → {String}

Returns a complete URL for the grant flow authentication and creates a state.

View Source lib/twitchtv.js, line 78

String

getAuthToken() → {String}

Returns the twitch user auth token. Used for login in twitch irc or api requests for user related information.

View Source lib/twitchtv.js, line 123

String

getChannel(channelidopt) → {Promise}

Gets a channel by the passed channelid or by the oauth token
Parameters:
Name Type Attributes Description
channelid String | Number <optional>
The channel id of the channel you want to get. Channel names are not supported.
See:

View Source lib/twitchtv.js, line 358

Returns a Promise that resolves with the deserialized json object
Promise

getChannelFollowers(channelidopt, options) → {Promise}

Gets users that follow the channel.
Parameters:
Name Type Attributes Default Description
channelid String | Number <optional>
Channel id of the channel you want the followers of.
options Object Options to control direction of the result.
limit Number <optional>
25 Maximum number of objects to return. Maximum: 100.
offset Number <optional>
0 Object offset for pagination of results.
cursor String <optional>
Tells the server where to start fetching the next set of results, in a multi-page response.
direction String <optional>
'desc' Direction of sorting. Valid values: asc (oldest first), desc (newest first).
See:

View Source lib/twitchtv.js, line 410

Returns a Promise that resolves with the deserialized json object
Promise

getChannelSubscribers(channelidopt, options) → {Promise}

Gets subscribers to the channel. Logged in user needs to have permission to view channel subscriber or you get a 401 error.
Parameters:
Name Type Attributes Default Description
channelid String | Number <optional>
Channel id of the channel you want the subscriber of.
options Object Options to control direction of the result.
limit Number <optional>
25 Maximum number of objects to return. Maximum: 100.
offset Number <optional>
0 Object offset for pagination of results.
direction String <optional>
'asc' Direction of sorting. Valid values: asc (oldest first), desc (newest first).
See:

View Source lib/twitchtv.js, line 457

Returns a Promise that resolves with the deserialized json object
Promise

getChannelVideos(channelid, options) → {Promise}

Gets a list of VODs (Video on Demand) from a specified channel.
Parameters:
Name Type Attributes Default Description
channelid String | Number Channel id of the channel you want the subscriber of.
options Object Options to control direction of the result.
limit Number <optional>
25 Maximum number of objects to return. Maximum: 100.
offset Number <optional>
0 Object offset for pagination of results.
broadcast_type String <optional>
'archive,highlight,upload' Constrains the type of videos returned. Valid values: (any combination of) archive, highlight, upload.
language String <optional>
Constrains the language of the videos that are returned; for example, en,es. Default: all languages.
sort String <optional>
'time' Sorting order of the returned objects. Valid values: views, time.
See:

View Source lib/twitchtv.js, line 505

Returns a Promise that resolves with the deserialized json object
Promise

getChatBadgesByChannel(channelid) → {Promise}

Loads channel badges. It's incomplete. If you want better badges use TwitchTv#getChatBadgeSetsByChannel.
Parameters:
Name Type Description
channelid String | Number Channel id of the channel you want the badges of.
See:

View Source lib/twitchtv.js, line 546

Returns a Promise that resolves with the deserialized json object
Promise

getChatBadgeSetsByChannel(channelidopt) → {Promise}

A more detailed alternative to TwitchTv#getChatBadgesByChannel. There is no official documentation and is now official api endpoint. See example for an example response.
Parameters:
Name Type Attributes Description
channelid String | Number <optional>
Channel id of the channel you want the badges of.

View Source lib/twitchtv.js, line 582

Returns a Promise that resolves with the deserialized json object
Promise
Example
// Example response:
{
  "badge_sets": {
    "subscriber": {
      "versions": {
        "0": {
          "image_url_1x": "https://static-cdn.jtvnw.net/badges/v1/7821fdef-7fd6-4085-a9b0-eae8952ce299/1",
          "image_url_2x": "https://static-cdn.jtvnw.net/badges/v1/7821fdef-7fd6-4085-a9b0-eae8952ce299/2",
          "image_url_4x": "https://static-cdn.jtvnw.net/badges/v1/7821fdef-7fd6-4085-a9b0-eae8952ce299/3",
          "description": "Subscriber",
          "title": "Subscriber",
          "click_action": "subscribe_to_channel",
          "click_url": ""
        }
      }
    }
  }
}

getChatEmoticonsBySet(emotesets) → {Promise}

Get emote sets.
Parameters:
Name Type Description
emotesets String Comma seperated list of emote set ids.
See:

View Source lib/twitchtv.js, line 627

Returns a Promise that resolves with the deserialized json object
Promise

getCheermotes(channel_idopt) → {Promise}

Retrieves the list of available cheermotes
Parameters:
Name Type Attributes Description
channel_id String <optional>
If this is specified, the cheermote for this channel is included in the response (if the channel owner has uploaded a channel-specific cheermote).
See:

View Source lib/twitchtv.js, line 770

Returns a Promise that resolves with the deserialized json object
Promise

getCollectionsByChannel(channelid, optionsopt) → {Promise}

Gets collections to a specified channel
Parameters:
Name Type Attributes Default Description
channelid String The channel you want the collections of
options Object <optional>
Options to filter or limit the response
limit String <optional>
10 Maximum number of most-recent objects to return. Maximum: 100.
cursor Number <optional>
Tells the server where to start fetching the next set of results in a multi-page response.
containing_item String <optional>
Returns only collections containing the specified video. Note this uses a video ID, not a collection item ID. Example: video:89917098.
See:

View Source lib/twitchtv.js, line 747

Returns a Promise that resolves with the deserialized json object
Promise

getStreamByUser(channelidopt, options) → {Promise}

Loads a stream object for a channel
Parameters:
Name Type Attributes Default Description
channelid String | Number <optional>
Channel id of the channel you want the stream for.
options Object Options to filter by stream type
steam_type String <optional>
'live' Constrains the type of streams returned. Valid values: live, playlist, all. Playlists are offline streams of VODs (Video on Demand) that appear live.
See:

View Source lib/twitchtv.js, line 662

Returns a Promise that resolves with the deserialized json object
Promise

getTeam(teamname) → {Promise}

Gets a specified team object
Parameters:
Name Type Description
teamname String The teamname that you want to get
See:

View Source lib/twitchtv.js, line 728

Returns a Promise that resolves with the deserialized json object
Promise

getUser(useridopt) → {Promise}

Gets a user by the passed userid or by the oauth token
Parameters:
Name Type Attributes Description
userid String | Number <optional>
The user id of the user you want to get. Usernames are not supported. Use TwitchTv#getUserByName to get the user by name.
See:

View Source lib/twitchtv.js, line 275

Returns a Promise that resolves with the deserialized json object
Promise

getUserByName(username) → {Promise}

Gets user objects by name.
Parameters:
Name Type Description
username String Username of the user you want to get. You can pass a comma seperated list (up to 100) to get multiple users at once. Display name is not supported.
See:

View Source lib/twitchtv.js, line 294

Returns a Promise that resolves with the deserialized json object
Promise

getUserFollows(useridopt, options) → {Promise}

Get the channels a user follows.
Parameters:
Name Type Attributes Default Description
userid String | Number <optional>
The user id of the user you want the follows of.
options Object Options to control direction and sorting of the result
limit Number <optional>
25 Maximum number of most-recent objects to return. Maximum: 100.
offset Number <optional>
0 Object offset for pagination of results.
direction String <optional>
'desc' Sorting direction. Valid values: asc (oldes first), desc (newest first).
sortby String <optional>
'created_at' Sorting key. Valid values: created_at, last_broadcast, login.
See:

View Source lib/twitchtv.js, line 312

Returns a Promise that resolves with the deserialized json object
Promise

isLoggedIn() → {Boolean}

Returns true if user is logged in.

View Source lib/twitchtv.js, line 132

Boolean

postAutoMod(action, msg_id) → {Promise}

Approve or deny a message filtered by AutoMod
Parameters:
Name Type Description
action String A string that is either 'approve' or 'deny'
msg_id String A string containing the message's id

View Source lib/twitchtv.js, line 640

Returns a Promise that resolves with an empty object
Promise

requestAPI(uri, query, authNeeded, postdataopt, methodopt) → {Promise}

Prepares and executes a request to the twitch api and parses the response
Parameters:
Name Type Attributes Default Description
uri String The URI to the api endpoint. Only the path is required, the host api.twitch.tv is prepended when the uri does not start with https://
query Object An object with all request parameters. Is being encoded for the uri. Must be passed but can be empty.
authNeeded Boolean Is user authorization required for this request. Oauth token is then passed on the request.
postdata Object <optional>
{} Optional post data. If there are properties in this object authNeeded is set to true and request method is set to put. Post data is serialized to a JSON string.
method String <optional>
GET Optional HTTP method. Defaults to GET (or PUT if postdata contains items)

View Source lib/twitchtv.js, line 146

Returns a Promise that resolves with the deserialized json object
Promise

searchGames(query, options) → {Promise}

Search for available games
Parameters:
Name Type Attributes Default Description
query String Search query. Must be at least 3 characters long, otherwise request is not being done.
options Object Options for filtering
live Boolean <optional>
false If true, returns only games that are live on at least one channel.
See:

View Source lib/twitchtv.js, line 707

Returns a Promise that resolves with the deserialized json object
Promise

setAuthToken(token)

Fills the user token and saves it in the localStorage.
Parameters:
Name Type Description
token String The token that is returned by the OAuth2 auth flow

View Source lib/twitchtv.js, line 112

startChannelCommercial(channelid, length) → {Promise}

Starts a commercial (advertisement) on a specified channel. This is valid only for channels that are Twitch partners. You cannot start a commercial more often than once every 8 minutes.
Parameters:
Name Type Description
channelid String | Number Channel id of the channel you want start commercials for
length Number The length of the commercial (in seconds). Valid values are 30, 60, 90, 120, 150, and 180.
See:

View Source lib/twitchtv.js, line 528

Returns a Promise that resolves with the deserialized json object
Promise

updateChannel(channelid, options) → {Promise}

Updates some channel data
Parameters:
Name Type Attributes Description
channelid String | Number The channel id of the channel you want to update. The logged in user must have permission for that or an http error 401 is returned.
options Object Options that should be changed. At least one property is required or no request is made (and therefore no callback called).
status String <optional>
Description of the broadcaster's status, displayed as a title on the channel page.
game String <optional>
Name of game.
delay String <optional>
Channel delay, in seconds. This inserts a delay in the live feed. Only channel owner can change this.
channel_feed_enabled Boolean <optional>
If true, the channel's feed is turned on. Only channel owner can change this.
See:

View Source lib/twitchtv.js, line 382

Returns a Promise that resolves with the deserialized json object
Promise

verifyState(state) → {Boolean}

Verifys if this returned state is one of the valid states and removes it from the local list.
Parameters:
Name Type Description
state String The state that is returned by the OAuth auth flow

View Source lib/twitchtv.js, line 97

Boolean