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
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.
- Start Commercial
- Get Extension Analytics
- Get Game Analytics (Documentation in progress)
- Get Bits Leaderboard
- Get Cheermotes
- Get Extension Transactions
- Get Channel Information
- Modify Channel Information
- Get Channel Editors
- Create Custom Rewards
- Delete Custom Reward
- Get Custom Reward
- Get Custom Reward Redemption
- Update Custom Reward
- Update Redemption Status
- Get Channel Emotes
- Get Global Emotes
- Get Emote Sets
- Get Channel Chat Badges
- Get Global Chat Badges
- Get Chat Settings
- Update Chat Settings
- Create Clip
- Get Clips
- Create Entitlement Grants Upload URL
- Get Code Status
- Get Drops Entitlements
- Redeem Code
- Get Extension Configuration Segment
- Set Extension Configuration Segment
- Set Extension Required Configuration
- Send Extension PubSub Message
- Get Live Channels
- Get Extension Secrets
- Create Extension Secret
- Send Extension Chat Message
- Get Extensions
- Get Released Extensions
- Get Extension Bits Products
- Update Extension Bits Product
- Create EventSub Subscription
- Delete EventSub Subscription
- Get EventSub Subscriptions
- Get Top Games
- Get Games
- Get Hype Train Events
- Check AutoMod Status
- Get Banned Events
- Get Banned Users
- Get Moderators
- Get Moderator Events
- Get Polls
- Create Poll
- End Poll
- Get Predictions
- Create Prediction
- End Prediction
- Get Channel Stream Schedule
- Get Channel iCalendar
- Update Channel Stream Schedule
- Create Channel Stream Schedule Segment
- Update Channel Stream Schedule Segment
- Delete Channel Stream Schedule Segment
- Search Categories
- Search Channels
- Get Stream Key
- Get Streams
- Create Stream Marker
- Get Stream Markers
- Get Broadcaster Subscriptions
- Get All Stream Tags
- Get Stream Tags
- Replace Stream Tags
- Get Users
- Update User
- Get Users Follows
- Create User Follows
- Delete User Follows
- Get User Block List
- Block User
- Unblock User
- Get User Extensions
- Get User Active Extensions
- Update User Extensions
- Get Videos
- Delete Videos
- Get Webhook Subscriptions
Guillaume Roux |
LaCremeDoree |
Lewis Holliday |