C# Class TwitchLib.TwitchApi

Show file Open project: swiftyspiffy/TwitchLib

Private Properties

Property Type Description
MakeGetRequest Task
MakeRestRequest Task
ValidClientId void
handleWebException void

Public Methods

Method Description
BlockUser ( string username, string blockedUsername, string accessToken = null ) : Task

Blocks a user.

Authenticated, required scope: user_blocks_edit

BroadcasterOnline ( string channel ) : Task

Retrieves the current status of the broadcaster.

ChannelHasUserSubscribed ( string username, string channel, string accessToken = null ) : Task

Retrieves whether a username is subscribed to a channel.

Authenticated, required scope: channel_check_subscription

DeleteChannelFeedPost ( string postId, string channel, string accessToken = null ) : void

Deletes a post on a Twitch channel's feed.

FollowChannel ( string username, string channel, string accessToken = null ) : Task

Follows a channel given by channel.

Authenticated, required scope: user_follows_edit

GetBlockedList ( string username, string accessToken = null, int limit = 25, int offset ) : Task>

Retrieves a list of blocked users a specific user has.

Authenticated, required scope: user_blocks_read

GetChannel ( string channel ) : Task

Retrieves a TwitchStream object containing API data related to a stream.

GetChannelBadges ( string channel ) : Task

Retrieves a channel's list of available chat badges.

GetChannelEditors ( string channel, string accessToken = null ) : Task>

Retrieves a string list of channel editor users.

Authenticated, required scope: channel_read

GetChannelFeed ( string channel, int limit = 10, string cursor = null ) : Task

Retrieves channel feed posts.

GetChannelFromSteamId ( string steamId ) : Task

Fetches Twitch channel name from a steam Id, if their Steam is connected to their Twitch.

GetChannelHosts ( string channel ) : Task>

Retrieves a string list of channels hosting a specified channel.

Note: This uses an undocumented API endpoint and reliability is not guaranteed. Additionally, this makes 2 API calls so limited use is recommended.

GetChannelVideos ( string channel, int limit = 10, int offset, bool onlyBroadcasts = false, bool onlyHls = false ) : Task>

Returns a list of videos ordered by time of creation, starting with the most recent.

GetChannelsObject ( string channel ) : Task

Retrieves a Channels object regarding a specific channel.

GetChatters ( string channel ) : Task>

Retrieves a list of all people currently chatting in a channel's chat.

GetFeaturedStreams ( int limit = 25, int offset ) : Task>

Retrieves all featured streams.

GetFollowedUsers ( string channel, int limit = 25, int offset, System.Enums sortKey = Enums.SortKey.CreatedAt ) : Task

Retrieves a list of followed users a specific user has.

GetGamesByPopularity ( int limit = 10, int offset ) : Task>

Execute a query to return the games with the most current viewers.

GetStream ( string channel ) : Task

Retrieves a collection of API data from a stream.

GetStreams ( List channels ) : Task>

Retrieves a collection of API data from multiple streams

GetSubscriberCount ( string channel, string accessToken = null ) : Task

Returns the amount of subscribers channel has.

Authenticated, required scope: channel_subscriptions

GetTeamMembers ( string teamName ) : Task>

Retrieves a TwitchTeamMember list of all members in a Twitch team.

Note: This uses an undocumented API endpoint and reliability is not guaranteed.

GetTwitchFollowers ( string channel, int limit = 25, string cursor = "-1", System.Enums direction = Enums.SortDirection.Descending ) : Task

Retrieves an ascending or descending list of followers from a specific channel.

GetUptime ( string channel ) : Task

Retrieves the current uptime of a stream, if it is online.

GetUser ( string username ) : Task

Retrieves a User object from Twitch Api and returns User object.

PostToChannelFeed ( string content, bool share, string channel, string accessToken = null ) : Task

Posts to a Twitch channel's feed.

ResetStreamKey ( string channel, string accessToken = null ) : Task

Resets the stream key of the channel.

Authenticated, required scope: channel_stream

RunCommercial ( System.Enums length, string channel, string accessToken = null ) : Task

Start a commercial on channel.

Authenticated, required scope: channel_commercial

SearchChannels ( string query, int limit = 25, int offset ) : Task>

Execute a search query on Twitch to find a list of channels.

SearchGames ( string query, bool live = false ) : Task>

Execute a search query on Twitch to find a list of games.

SearchStreams ( string query, int limit = 25, int offset, bool hls = null ) : Task>

Execute a search query on Twitch to find a list of streams.

SetAccessToken ( string accessToken ) : void

Sets Access Token, which is saved in memory. This is not necessary, as tokens can be passed into Api calls.

SetClientId ( string clientId, bool disableClientIdValidation = false ) : void

Sets ClientId, which is required for all API calls. Also validates ClientId. Client-Id to bind to TwitchApi. Forcefully disables Client-Id validation.

StreamIsLive ( string channel ) : Task

Checks if a stream is live or not.

UnblockUser ( string username, string blockedUsername, string accessToken = null ) : void

Unblocks a user.

Authenticated, required scope: user_blocks_edit

UnfollowChannel ( string username, string channel, string accessToken = null ) : void

Unfollows a channel given by channel.

Authenticated, required scope: user_follows_edit

UpdateStreamDelay ( int delay, string channel, string accessToken = null ) : Task

Updates the delay of a channel.

Authenticated, required scope: channel_editor

UpdateStreamGame ( string game, string channel, string accessToken = null ) : Task

Update the game the channel is currently playing.

Authenticated, required scope: channel_editor

UpdateStreamTitle ( string status, string channel, string accessToken = null ) : Task

Update the status of a channel.

Authenticated, required scope: channel_editor

UpdateStreamTitleAndGame ( string status, string game, string channel, string accessToken = null ) : Task

Update the status and game of a channel.

UserFollowsChannel ( string username, string channel ) : Task

Retrieves whether a specified user is following the specified user.

ValidClientId ( string clientId, bool updateClientIdOnSuccess = true ) : Task

Validates a Client-Id and optionally updates it.

Private Methods

Method Description
MakeGetRequest ( string url, string accessToken = null ) : Task
MakeRestRequest ( string url, string method, string requestData = null, string accessToken = null ) : Task
ValidClientId ( ) : void
handleWebException ( WebException e ) : void

Method Details

BlockUser() public static method

Blocks a user.

Authenticated, required scope: user_blocks_edit

public static BlockUser ( string username, string blockedUsername, string accessToken = null ) : Task
username string User who's blocked list to add to.
blockedUsername string User to block.
accessToken string This call requires an access token.
return Task

BroadcasterOnline() public static method

Retrieves the current status of the broadcaster.
public static BroadcasterOnline ( string channel ) : Task
channel string The name of the broadcaster to check.
return Task

ChannelHasUserSubscribed() public static method

Retrieves whether a username is subscribed to a channel.

Authenticated, required scope: channel_check_subscription

public static ChannelHasUserSubscribed ( string username, string channel, string accessToken = null ) : Task
username string The user to check subscription status for.
channel string The channel to check against.
accessToken string An oauth token with the required scope.
return Task

DeleteChannelFeedPost() public static method

Deletes a post on a Twitch channel's feed.
public static DeleteChannelFeedPost ( string postId, string channel, string accessToken = null ) : void
postId string Integer Id of feed post to delete.
channel string Channel where the post resides.
accessToken string OAuth access token with channel_feed_edit scope.
return void

FollowChannel() public static method

Follows a channel given by channel.

Authenticated, required scope: user_follows_edit

public static FollowChannel ( string username, string channel, string accessToken = null ) : Task
username string The username of the user trying to follow the given channel.
channel string The channel to follow.
accessToken string An oauth token with the required scope.
return Task

GetBlockedList() public static method

Retrieves a list of blocked users a specific user has.

Authenticated, required scope: user_blocks_read

public static GetBlockedList ( string username, string accessToken = null, int limit = 25, int offset ) : Task>
username string Username of user to fetch blocked list of.
accessToken string This call requires an access token.
limit int Limit output from Twitch Api. Default 25, max 100.
offset int Offset out from Twitch Api. Default 0.
return Task>

GetChannel() public static method

Retrieves a TwitchStream object containing API data related to a stream.
public static GetChannel ( string channel ) : Task
channel string The name of the channel to search for.
return Task

GetChannelBadges() public static method

Retrieves a channel's list of available chat badges.
public static GetChannelBadges ( string channel ) : Task
channel string The channel to fetch available badges from.
return Task

GetChannelEditors() public static method

Retrieves a string list of channel editor users.

Authenticated, required scope: channel_read

public static GetChannelEditors ( string channel, string accessToken = null ) : Task>
channel string The channel to fetch editors from.
accessToken string An access token with the required scope.
return Task>

GetChannelFeed() public static method

Retrieves channel feed posts.
public static GetChannelFeed ( string channel, int limit = 10, string cursor = null ) : Task
channel string Channel to fetch feed posts from.
limit int Applied limit (default 10, max 100)
cursor string Used for pagination.
return Task

GetChannelFromSteamId() public static method

Fetches Twitch channel name from a steam Id, if their Steam is connected to their Twitch.
public static GetChannelFromSteamId ( string steamId ) : Task
steamId string The steam id of the user whose Twitch channel is requested.
return Task

GetChannelHosts() public static method

Retrieves a string list of channels hosting a specified channel.

Note: This uses an undocumented API endpoint and reliability is not guaranteed. Additionally, this makes 2 API calls so limited use is recommended.

public static GetChannelHosts ( string channel ) : Task>
channel string The name of the channel to search for.
return Task>

GetChannelVideos() public static method

Returns a list of videos ordered by time of creation, starting with the most recent.
public static GetChannelVideos ( string channel, int limit = 10, int offset, bool onlyBroadcasts = false, bool onlyHls = false ) : Task>
channel string The channel to retrieve the list of videos from.
limit int Maximum number of objects in array. Default is 10. Maximum is 100.
offset int Object offset for pagination. Default is 0.
onlyBroadcasts bool Returns only broadcasts when true. Otherwise only highlights are returned. Default is false.
onlyHls bool Returns only HLS VoDs when true. Otherwise only non-HLS VoDs are returned. Default is false.
return Task>

GetChannelsObject() public static method

Retrieves a Channels object regarding a specific channel.
public static GetChannelsObject ( string channel ) : Task
channel string The channel to fetch Channels object about.
return Task

GetChatters() public static method

Retrieves a list of all people currently chatting in a channel's chat.
public static GetChatters ( string channel ) : Task>
channel string The channel to retrieve the chatting people for.
return Task>

GetFeaturedStreams() public static method

Retrieves all featured streams.
public static GetFeaturedStreams ( int limit = 25, int offset ) : Task>
limit int
offset int
return Task>

GetFollowedUsers() public static method

Retrieves a list of followed users a specific user has.
public static GetFollowedUsers ( string channel, int limit = 25, int offset, System.Enums sortKey = Enums.SortKey.CreatedAt ) : Task
channel string Channel to fetch followed users
limit int Default is 25, max is 100, min is 0
offset int Integer representing list offset
sortKey System.Enums Enum representing sort order.
return Task

GetGamesByPopularity() public static method

Execute a query to return the games with the most current viewers.
public static GetGamesByPopularity ( int limit = 10, int offset ) : Task>
limit int The number of listings to return, default to 10.
offset int The number of listings to offset the returned listings, default to 0.
return Task>

GetStream() public static method

Retrieves a collection of API data from a stream.
Throws StreamOfflineException if stream is offline. Throws BadResourceException if the passed channel is invalid.
public static GetStream ( string channel ) : Task
channel string The channel to retrieve the data for.
return Task

GetStreams() public static method

Retrieves a collection of API data from multiple streams
public static GetStreams ( List channels ) : Task>
channels List List of channels.
return Task>

GetSubscriberCount() public static method

Returns the amount of subscribers channel has.

Authenticated, required scope: channel_subscriptions

public static GetSubscriberCount ( string channel, string accessToken = null ) : Task
channel string The channel to retrieve the subscriptions from.
accessToken string An oauth token with the required scope.
return Task

GetTeamMembers() public static method

Retrieves a TwitchTeamMember list of all members in a Twitch team.

Note: This uses an undocumented API endpoint and reliability is not guaranteed.

public static GetTeamMembers ( string teamName ) : Task>
teamName string The name of the Twitch team to search for.
return Task>

GetTwitchFollowers() public static method

Retrieves an ascending or descending list of followers from a specific channel.
public static GetTwitchFollowers ( string channel, int limit = 25, string cursor = "-1", System.Enums direction = Enums.SortDirection.Descending ) : Task
channel string The channel to retrieve the followers from.
limit int Maximum number of objects in array. Default is 25. Maximum is 100.
cursor string Twitch uses cursoring to paginate long lists of followers. Check _cursor in response body and set cursor to this value to get the next page of results, or use _links.next to navigate to the next page of results.
direction System.Enums Creation date sorting direction.
return Task

GetUptime() public static method

Retrieves the current uptime of a stream, if it is online.
public static GetUptime ( string channel ) : Task
channel string The channel to retrieve the uptime for.
return Task

GetUser() public static method

Retrieves a User object from Twitch Api and returns User object.
public static GetUser ( string username ) : Task
username string Name of the user you wish to fetch from Twitch.
return Task

PostToChannelFeed() public static method

Posts to a Twitch channel's feed.
public static PostToChannelFeed ( string content, bool share, string channel, string accessToken = null ) : Task
content string The content of the message being posted.
share bool If set to true, and enabled on account, will tweet out post.
channel string Channel to post feed post to.
accessToken string OAuth access token with channel_feed_edit scope, not needed if already set.
return Task

ResetStreamKey() public static method

Resets the stream key of the channel.

Authenticated, required scope: channel_stream

public static ResetStreamKey ( string channel, string accessToken = null ) : Task
channel string The channel to reset the stream key for.
accessToken string An oauth token with the required scope.
return Task

RunCommercial() public static method

Start a commercial on channel.

Authenticated, required scope: channel_commercial

public static RunCommercial ( System.Enums length, string channel, string accessToken = null ) : Task
length System.Enums Length of commercial break in seconds. Default value is 30. You can only trigger a commercial once every 8 minutes.
channel string The channel to start a commercial on.
accessToken string An oauth token with the required scope.
return Task

SearchChannels() public static method

Execute a search query on Twitch to find a list of channels.
public static SearchChannels ( string query, int limit = 25, int offset ) : Task>
query string A url-encoded search query.
limit int Maximum number of objects in array. Default is 25. Maximum is 100.
offset int Object offset for pagination. Default is 0.
return Task>

SearchGames() public static method

Execute a search query on Twitch to find a list of games.
public static SearchGames ( string query, bool live = false ) : Task>
query string A url-encoded search query.
live bool If set to true, only games with active streams will be found.
return Task>

SearchStreams() public static method

Execute a search query on Twitch to find a list of streams.
public static SearchStreams ( string query, int limit = 25, int offset, bool hls = null ) : Task>
query string A url-encoded search query.
limit int Maximum number of objects in array. Default is 25. Maximum is 100.
offset int Object offset for pagination. Default is 0.
hls bool If set to true, only returns streams using HLS, if set to false only returns non-HLS streams. Default is null.
return Task>

SetAccessToken() public static method

Sets Access Token, which is saved in memory. This is not necessary, as tokens can be passed into Api calls.
public static SetAccessToken ( string accessToken ) : void
accessToken string Twitch account OAuth token to store in memory.
return void

SetClientId() public static method

Sets ClientId, which is required for all API calls. Also validates ClientId. Client-Id to bind to TwitchApi. Forcefully disables Client-Id validation.
public static SetClientId ( string clientId, bool disableClientIdValidation = false ) : void
clientId string
disableClientIdValidation bool
return void

StreamIsLive() public static method

Checks if a stream is live or not.
public static StreamIsLive ( string channel ) : Task
channel string The channel to retrieve live status for.
return Task

UnblockUser() public static method

Unblocks a user.

Authenticated, required scope: user_blocks_edit

public static UnblockUser ( string username, string blockedUsername, string accessToken = null ) : void
username string User who's blocked list to unblock from.
blockedUsername string User to unblock.
accessToken string This call requires an access token.
return void

UnfollowChannel() public static method

Unfollows a channel given by channel.

Authenticated, required scope: user_follows_edit

public static UnfollowChannel ( string username, string channel, string accessToken = null ) : void
username string The username of the user trying to follow the given channel.
channel string The channel to unfollow.
accessToken string An oauth token with the required scope.
return void

UpdateStreamDelay() public static method

Updates the delay of a channel.

Authenticated, required scope: channel_editor

public static UpdateStreamDelay ( int delay, string channel, string accessToken = null ) : Task
delay int Channel delay in seconds.
channel string The channel to update.
accessToken string The channel owner's access token and the required scope.
return Task

UpdateStreamGame() public static method

Update the game the channel is currently playing.

Authenticated, required scope: channel_editor

public static UpdateStreamGame ( string game, string channel, string accessToken = null ) : Task
game string Game category to be classified as.
channel string The channel to update.
accessToken string An oauth token with the required scope.
return Task

UpdateStreamTitle() public static method

Update the status of a channel.

Authenticated, required scope: channel_editor

public static UpdateStreamTitle ( string status, string channel, string accessToken = null ) : Task
status string Channel's title.
channel string The channel to update.
accessToken string An oauth token with the required scope.
return Task

UpdateStreamTitleAndGame() public static method

Update the status and game of a channel.
public static UpdateStreamTitleAndGame ( string status, string game, string channel, string accessToken = null ) : Task
status string Channel's title.
game string Game category to be classified as.
channel string The channel to update.
accessToken string An oauth token with the required scope.
return Task

UserFollowsChannel() public static method

Retrieves whether a specified user is following the specified user.
public static UserFollowsChannel ( string username, string channel ) : Task
username string The user to check the follow status of.
channel string The channel to check against.
return Task

ValidClientId() public static method

Validates a Client-Id and optionally updates it.
public static ValidClientId ( string clientId, bool updateClientIdOnSuccess = true ) : Task
clientId string Client-Id string to be validated.
updateClientIdOnSuccess bool Updates Client-Id if passed Client-Id is valid.
return Task