TwitchAPI
Inherits: Object
Main singleton for accessing the Twitch API with automatic polling.
Description
TwitchAPI provides a self-contained interface to the Twitch Helix API. It automatically polls for HTTP responses every physics frame, eliminating the need for manual polling. Access different API categories through getter methods like get_users(), get_streams(), get_chat(), etc. Connect to signals request_completed and request_failed to handle responses asynchronously.
Example:
func _ready():
TwitchAPI.configure("your_client_id", "your_access_token")
TwitchAPI.request_completed.connect(_on_request_completed)
TwitchAPI.get_users().get_users({"login": ["twitch"]})
func _on_request_completed(signal_name: String, response_code: int, data: Dictionary):
print("Success: ", signal_name, " - ", data)
Tutorials
Methods
void |
|
get_ads() |
|
get_bits() |
|
get_chat() |
|
get_http_client() const |
|
get_rate_limit_remaining() const |
|
get_rate_limit_reset() const |
|
is_busy() const |
|
void |
poll() |
query_string_from_dict(params: Dictionary) const |
|
void |
set_access_token(token: String) |
void |
set_client_id(client_id: String) |
Signals
rate_limit_warning(remaining: int, reset_time: int) 🔗
Emitted when the remaining API rate limit drops below 100 requests. remaining is the number of requests left, and reset_time is the Unix timestamp when the limit resets.
request_completed(signal_name: String, response_code: int, data: Dictionary) 🔗
Emitted when an API request completes successfully (HTTP 2xx status). signal_name identifies which request completed, response_code is the HTTP status code, and data contains the parsed JSON response.
request_failed(signal_name: String, error_code: int, message: String) 🔗
Emitted when an API request fails (HTTP error status or connection issue). signal_name identifies which request failed, error_code is the HTTP status code or error code, and message contains the error description.
Method Descriptions
void configure(client_id: String, access_token: String) 🔗
Configures the API with Twitch credentials and enables automatic polling. This must be called before making any API requests. Both client_id (from your Twitch Developer Console) and access_token (OAuth token) are required.
TwitchAdsRequests get_ads() 🔗
Returns the Ads API category handler for starting commercials, getting ad schedules, and snoozing ads.
TwitchAnalyticsRequests get_analytics() 🔗
Returns the Analytics API category handler for accessing extension and game analytics reports.
TwitchBitsRequests get_bits() 🔗
Returns the Bits API category handler for accessing Bits leaderboards, cheermotes, and extension transactions.
TwitchChannelPointsRequests get_channel_points() 🔗
Returns the Channel Points API category handler for managing custom rewards and redemptions.
TwitchChannelsRequests get_channels() 🔗
Returns the Channels API category handler for accessing and modifying channel information, editors, and followers.
TwitchChatRequests get_chat() 🔗
Returns the Chat API category handler for sending messages, managing emotes, badges, and chat settings.
TwitchClipsRequests get_clips() 🔗
Returns the Clips API category handler for creating and retrieving video clips.
TwitchGamesRequests get_games() 🔗
Returns the Games API category handler for accessing game information and top games by viewer count.
TwitchHTTPClient get_http_client() const 🔗
There is currently no description for this method. Please help us by contributing one!
TwitchModerationRequests get_moderation() 🔗
Returns the Moderation API category handler for bans, timeouts, AutoMod, blocked terms, moderators, and VIPs.
int get_rate_limit_remaining() const 🔗
Returns the number of API requests remaining before hitting the rate limit. Returns -1 if no requests have been made yet.
int get_rate_limit_reset() const 🔗
Returns the Unix timestamp when the rate limit resets. Returns 0 if no requests have been made yet.
TwitchStreamsRequests get_streams() 🔗
Returns the Streams API category handler for accessing stream information, stream keys, and stream markers.
TwitchUsersRequests get_users() 🔗
Returns the Users API category handler for accessing user information, blocking users, and managing extensions.
Returns true if there are requests in the queue or a request is currently being processed.
void poll() 🔗
Manually polls the HTTP client to process requests. This is automatically called every frame after configure() is invoked, so manual polling is typically not needed.
String query_string_from_dict(params: Dictionary) const 🔗
Converts a Dictionary of parameters into a URL query string. Arrays are expanded into multiple parameters with the same key.
void set_access_token(token: String) 🔗
Updates the OAuth access token used for API authentication. Useful when refreshing expired tokens.
void set_client_id(client_id: String) 🔗
Updates the Twitch application Client ID used for API authentication.