twitch_api
A wrapper in pure Dart to connect to Twitch.tv using OAuth implicit authentication.
All the endpoints are implemented as defined in the Twitch API Reference
Getting started
NOTE: This package is in its early stage, please be patient until more methods are implemented or do not hesitate to open a merge request if you added support for an endpoint. Currently I do not have a roadmap of the endpoint I am going to add in priority so do not hesitate to open an issue to make suggestions depending of your needs.
To use this package you will need to register an application on the Twitch developer console to get a client ID.
After registering your application you will need to instantiate the TwitchClient class from the package with your clientId and your redirectUri .
import 'package:twitch_api/twitch_api.dart';
final _twitchClient = TwitchClient(
clientId: clientId,
redirectUri: redirectUri,
);
Now that you have initialized the client the last step before using the method will be to manage the first connection with your twitch account and initialize the token you will receive. You can find a complete example of an implementation using the package flutter_webview_plugin.
const clientId = "<YOUR_CLIENT_ID>";
const redirectUri = "<YOUR_REDIRECT_URL>"; // ex: "http://localhost/"
final _twitchClient = TwitchClient(
clientId: clientId,
redirectUri: redirectUri,
);
final _flutterWebviewPlugin = FlutterWebviewPlugin();
// First authentication through a webview
Future<TwitchToken> _openConnectionPage({
List<TwitchApiScope> scopes = const [],
}) {
// Listen for url changes to detect redirection on our redirectUri.
_flutterWebviewPlugin.onUrlChanged.listen((url) {
if (url.startsWith(_twitchClient.redirectUri)) {
// After you got to your redirectUri you can initialize the token.
_twitchClient.initializeToken(TwitchToken.fromUrl(url));
// Close the webview
_flutterWebviewPlugin.close();
}
});
// When the webview is closed pop the current route.
_flutterWebviewPlugin.onDestroy.listen((_) => Navigator.pop(context));
// Get authorization URL for the connection with the webview.
final _url = _twitchClient.authorizeUri(scopes);
return Navigator.push(
context,
MaterialPageRoute(
builder: (context) => WebViewPage(_url.toString()),
),
).then((_) => _twitchClient.twitchHttpClient.validateToken());
}
Now you are ready to use the methods implemented in Supported Endpoints section.
Supported Endpoints
Ads
xStart Commercial
Analytics
xGet Extension AnalyticsxGet Game Analytics (Documentation in progress)
Bits
xGet Bits LeaderboardxGet CheermotesxGet Extension Transactions
Channels
xGet Channel InformationxModify Channel InformationxGet Channel Editors
Channel Points
xCreate Custom RewardsxDelete Custom RewardxGet Custom RewardxGet Custom Reward RedemptionxUpdate Custom RewardxUpdate Redemption Status
Chat
xGet Channel EmotesxGet Global EmotesxGet Emote SetsxGet Channel Chat BadgesxGet Global Chat BadgesxGet Chat SettingsUpdate Chat Settings
Clips
Create ClipGet Clips
Entitlements
Create Entitlement Grants Upload URLGet Code StatusGet Drops EntitlementsRedeem Code
Extensions
Get Extension Configuration SegmentSet Extension Configuration SegmentSet Extension Required ConfigurationSend Extension PubSub MessageGet Live ChannelsGet Extension SecretsCreate Extension SecretSend Extension Chat MessageGet ExtensionsGet Released ExtensionsGet Extension Bits ProductsUpdate Extension Bits Product
EventSub
Create EventSub SubscriptionDelete EventSub SubscriptionGet EventSub Subscriptions
Games
xGet Top GamesxGet Games
Hype Train
Get Hype Train Events
Moderation
Check AutoMod StatusGet Banned EventsGet Banned UsersGet ModeratorsGet Moderator Events
Polls
Get PollsCreate PollEnd Poll
Predictions
Get PredictionsCreate PredictionEnd Prediction
Schedule
Get Channel Stream ScheduleGet Channel iCalendarUpdate Channel Stream ScheduleCreate Channel Stream Schedule SegmentUpdate Channel Stream Schedule SegmentDelete Channel Stream Schedule Segment
Search
xSearch CategoriesxSearch Channels
Streams
Get Stream KeyxGet StreamsCreate Stream MarkerGet Stream Markers
Subscriptions
xGet Broadcaster Subscriptions
Tags
Get All Stream TagsGet Stream TagsReplace Stream Tags
Users
xGet UsersUpdate UserxGet Users FollowsCreate User FollowsDelete User FollowsGet User Block ListBlock UserUnblock UserGet User ExtensionsGet User Active ExtensionsUpdate User Extensions
Videos
Get VideosDelete Videos
Webhooks
Get Webhook Subscriptions
Contributors
|
Guillaume Roux |
Lewis Holliday |