TwurpleAuthenticationGetting dataExamplesFAQMigration

Choosing the correct user

In general, Twurple automatically decides for you which user a call should be executed as.

There are mostly three categories of requests:

  1. For calls that require authentication, the required user (or the app token) is always automatically chosen, and if that user is not available in your auth provider, the call will fail.

  2. Other calls, such as getting a stream by user ID, are in the context of a user, but do not require authentication. In this case, Twurple will try using that user's authentication, but if it's not available, fall back to app authentication.

  3. Lastly, there are a few calls where user context can never be determined, so they will always be called using an app token:

    CategoryMethod
    BitsHelixBitsApi#getCheermotes (without broadcaster parameter)
    ChannelHelixChannelApi#getChannelInfoByIds
    ChatHelixChatApi#getGlobalBadges
    ChatHelixChatApi#getGlobalEmotes
    ChatHelixChatApi#getEmotesFromSets
    ChatHelixChatApi#getColorsForUsers
    ClipsHelixClipApi#getClipsForGame
    ClipsHelixClipApi#getClipsByIds
    ClipsHelixClipApi#getClipById
    ExtensionsHelixExtensionsApi#getReleasedExtension
    Gamesevery method of HelixGameApi
    Searchevery method of HelixSearchApi
    StreamsHelixStreamApi#getStreams
    StreamsHelixStreamApi#getStreamsByUserNames
    StreamsHelixStreamApi#getStreamByUserName
    StreamsHelixStreamApi#getStreamsByUserIds
    TeamsHelixTeamApi#getTeamById
    TeamsHelixTeamApi#getTeamByName
    UsersHelixUserApi#getUsersByIds
    UsersHelixUserApi#getUsersByNames
    UsersHelixUserApi#getUserByName
    VideosHelixVideoApi#getVideosByIds
    VideosHelixVideoApi#getVideoById
    VideosHelixVideoApi#getVideosByGame

    Deprecated methods & paginated variants have been omitted for brevity.

Overriding optional user context

For the resources in categories 2 and 3, you can override the user context to a specified user ID using the asUser method:

const videoId = await apiClient.asUser('125328655', ctx => {
	const video = ctx.videos.getVideoById(videoId);
	return video.id;
});

Alternatively, you can use intents using the ApiClient#asIntent method.