Class

TwitchHelix

TwitchHelix(options)

Constructor

new TwitchHelix(options)

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
token String <optional>
A string with an bearer token. If this is omitted token will be loaded from localStroage if possible

View Source lib/twitchhelix.js, line 3

Members

String

clientid

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

View Source lib/twitchhelix.js, line 18

String

redirecturi

The redirect uri that ist set in the app settings.

View Source lib/twitchhelix.js, line 23

Array

scope

An array with the required permission scopes.

View Source lib/twitchhelix.js, line 28

String

userid

User id of the logged in user.

View Source lib/twitchhelix.js, line 39

null | Object

userobj

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

View Source lib/twitchhelix.js, line 44

Methods

createStreamMarker(query) → {Promise}

Creates a marker in the stream of a user specified by a user ID. A marker is an arbitrary point in a stream that the broadcaster wants to mark; e.g., to easily return to later.
Parameters:
Name Type Attributes Description
query Object An object with request parameters
user_id String ID of the broadcaster in whose live stream the marker is created.
description String <optional>
Description of or comments on the marker.
See:

View Source lib/twitchhelix.js, line 383

Returns a Promise that resolves with a single response object if the request is done
Promise

getAuthImplicitGrantFlowUrl() → {String}

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

View Source lib/twitchhelix.js, line 67

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/twitchhelix.js, line 115

String

getClips(query) → {Promise}

Gets clip information by clip ID (one or more), broadcaster ID (one only), or game ID (one only).
Parameters:
Name Type Attributes Description
query Object An object with request parameters
id Array.<String> <optional>
ID of the clip being queried. Limit: 100.
broadcaster_id String <optional>
ID of the broadcaster for whom clips are returned. The number of clips returned is determined by the first query-string parameter (default: 20). Results are ordered by view count.
game_id String <optional>
ID of the game for which clips are returned. The number of clips returned is determined by the first query-string parameter (default: 20). Results are ordered by view count.
after String <optional>
Cursor for forward pagination: tells the server where to start fetching the next set of results, in a multi-page response. This applies only to queries specifying broadcaster_id or game_id. The cursor value specified here is from the pagination response field of a prior query.
before String <optional>
Cursor for backward pagination: tells the server where to start fetching the next set of results, in a multi-page response. This applies only to queries specifying broadcaster_id or game_id. The cursor value specified here is from the pagination response field of a prior query.
ended_at String <optional>
Ending date/time for returned clips, in RFC3339 format. (Note that the seconds value is ignored.) If this is specified, started_at also must be specified; otherwise, the time period is ignored.
first Number <optional>
Maximum number of objects to return. Maximum: 100. Default: 20.
started_at String <optional>
Starting date/time for returned clips, in RFC3339 format. (Note that the seconds value is ignored.) If this is specified, ended_at also should be specified; otherwise, the ended_at date/time will be 1 week after the started_at value.
See:

View Source lib/twitchhelix.js, line 442

Returns a Promise that resolves with a single response object if the request is done
Promise

getGames(id, name) → {Promise}

Gets game information by game ID or name. At minimum, id or name must be provided for a query to be valid.
Parameters:
Name Type Description
id Array.<String> Game ID. At most 100 id values can be specified. Will be omitted when empty.
name Array.<String> Game name. The name must be an exact match. For instance, “Pokemon” will not return a list of Pokemon games; instead, query the specific Pokemon game(s) in which you are interested. At most 100 name values can be specified. Will be omitted when empty.
See:

View Source lib/twitchhelix.js, line 408

Returns a Promise that resolves with a single response object if the request is done
Promise

getStreams(query) → {Promise}

Gets information about active streams. Streams are returned sorted by number of current viewers, in descending order. Across multiple pages of results, there may be duplicate or missing streams, as viewers join and leave streams.
Parameters:
Name Type Attributes Description
query Object An object with request parameters
after String <optional>
Cursor for forward pagination: tells the server where to start fetching the next set of results, in a multi-page response. The cursor value specified here is from the pagination response field of a prior query.
before String <optional>
Cursor for backward pagination: tells the server where to start fetching the next set of results, in a multi-page response. The cursor value specified here is from the pagination response field of a prior query.
community_id Array.<String> <optional>
Returns streams in a specified community ID. You can specify up to 100 IDs.
first Number <optional>
Maximum number of objects to return. Maximum: 100. Default: 20.
game_id Array.<String> <optional>
Returns streams broadcasting a specified game ID. You can specify up to 100 IDs.
language Array.<String> <optional>
Stream language. You can specify up to 100 languages.
user_id Array.<String> <optional>
Returns streams broadcast by one or more specified user IDs. You can specify up to 100 IDs.
user_login Array.<String> <optional>
Returns streams broadcast by one or more specified user login names. You can specify up to 100 names.
See:

View Source lib/twitchhelix.js, line 357

Returns a Promise that resolves with a single response object if the request is done
Promise

getUsers(query) → {Promise}

Gets information about one or more specified Twitch users. Users are identified by optional user IDs and/or login name. If neither a user ID nor a login name is specified, the user is looked up by Bearer token.
Parameters:
Name Type Attributes Description
query Object An object with request parameters
id Array.<String> <optional>
String array of user ids (max 100 entries)
login Array.<String> <optional>
String array of user login names (max 100 entries)
See:

View Source lib/twitchhelix.js, line 298

Returns a Promise that resolves with a single response object if the request is done
Promise

getUsersFollows(from_id, to_id, firstopt, afteropt) → {Promise}

Gets information on follow relationships between two Twitch users. Information returned is sorted in order, most recent follow first. This can return information like “who is lirik following,” “who is following lirik,” or “is user X following user Y.” At minimum, from_id or to_id must be provided for a query to be valid.
Parameters:
Name Type Attributes Description
from_id String User ID. The request returns information about users who are being followed by the from_id user. Will be omitted when empty.
to_id String User ID. The request returns information about users who are following the to_id user. Will be omitted when empty.
first Number <optional>
Maximum number of objects to return. Maximum: 100. Default: 20.
after String <optional>
Cursor for forward pagination: tells the server where to start fetching the next set of results, in a multi-page response.
See:

View Source lib/twitchhelix.js, line 320

Returns a Promise that resolves with a single response object if the request is done
Promise

isLoggedIn() → {Boolean}

Returns true if user is logged in.

View Source lib/twitchhelix.js, line 124

Boolean

requestAPI(uri, query, authNeededopt, postdataopt, noretryopt, method=opt) → {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 <optional>
false 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.
noretry Boolean <optional>
false If this is set to true the request will not be retried after a server error response
method= String <optional>
Overwrite HTTP method

View Source lib/twitchhelix.js, line 154

Returns a Promise that resolves with a single response object if the request is done
Promise
Example
twitchtv.requestAPI(
    // uri
    '/helix/users',

    // query
    {
        login: ['pakl']
    },

    // authNeeded
    false
).then((data) => {
    // Do something with data
})

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/twitchhelix.js, line 101

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/twitchhelix.js, line 86

Boolean