In general, Twurple automatically decides for you which user a call should be executed as.
There are mostly three categories of requests:
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.
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.
Lastly, there are a few calls where user context can never be determined, so they will always be called using an app token:
Category | Method |
---|---|
Bits | HelixBitsApi#getCheermotes (without broadcaster parameter) |
Channel | HelixChannelApi#getChannelInfoByIds |
Chat | HelixChatApi#getGlobalBadges |
Chat | HelixChatApi#getGlobalEmotes |
Chat | HelixChatApi#getEmotesFromSets |
Chat | HelixChatApi#getColorsForUsers |
Clips | HelixClipApi#getClipsForGame |
Clips | HelixClipApi#getClipsByIds |
Clips | HelixClipApi#getClipById |
Extensions | HelixExtensionsApi#getReleasedExtension |
Games | every method of HelixGameApi |
Search | every method of HelixSearchApi |
Streams | HelixStreamApi#getStreams |
Streams | HelixStreamApi#getStreamsByUserNames |
Streams | HelixStreamApi#getStreamByUserName |
Streams | HelixStreamApi#getStreamsByUserIds |
Teams | HelixTeamApi#getTeamById |
Teams | HelixTeamApi#getTeamByName |
Users | HelixUserApi#getUsersByIds |
Users | HelixUserApi#getUsersByNames |
Users | HelixUserApi#getUserByName |
Videos | HelixVideoApi#getVideosByIds |
Videos | HelixVideoApi#getVideoById |
Videos | HelixVideoApi#getVideosByGame |
Deprecated methods & paginated variants have been omitted for brevity.
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.