TwitchHelix(options)

new TwitchHelix(options)

Parameters:
Name Type Description
options Object Options for the TwitchTv object
Properties
Name Type Attributes Description
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

Members

clientid :String

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

redirecturi :String

The redirect uri that ist set in the app settings.

scope :Array

An array with the required permission scopes.

userid :String

User id of the logged in user.

userobj :null|Object

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

Methods

getAuthImplicitGrantFlowUrl() → {String}

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

getAuthToken() → {String}

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

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.
Returns:
Promise - Returns a Promise that resolves with a single response object if the request is done
See:

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 Description
query Object An object with request parameters
Properties
Name Type Attributes Description
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.
Returns:
Promise - Returns a Promise that resolves with a single response object if the request is done
See:

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 Description
query Object An object with request parameters
Properties
Name Type Attributes Description
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)
Returns:
Promise - Returns a Promise that resolves with a single response object if the request is done
See:

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.
Returns:
Promise - Returns a Promise that resolves with a single response object if the request is done
See:

isLoggedIn() → {Boolean}

Returns true if user is logged in.
Returns:
Boolean

requestAPI(uri, query, authNeeded, postdataopt) → {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.
Returns:
Promise - Returns a Promise that resolves with a single response object if the request is done
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

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
Returns:
Boolean