gundyr
Gundyr provides an easy to use interface to the Helix Twitch API and Twitch PubSub.
It handles both app access as well as user access tokens. All tokens used are automatically refreshed.
This is a work in progress and not all Helix or PubSub endpoints are supported yet.
Install
$ go get github.com/kelr/gundyr
Docs
Documentation can be found at godoc. Examples can be found in the examples directory.
Usage
Helix - Getting a User ID
cfg := &gundyr.HelixConfig{
ClientID: clientID,
ClientSecret: clientSecret,
}
c, err := gundyr.NewHelix(cfg)
if err != nil {
log.Fatal(err)
}
userID, err := c.UserToID("kyrotobi")
if err != nil {
log.Fatal(err)
}
log.Println(userID)
Helix - Using User Access Tokens
If an OAuth2 token is not provided to HelixConfig, authentication will attempt to use the OAuth2 Client Credentials flow to obtain a App Access token.
cfg := &gundyr.HelixConfig{
ClientID: clientID,
ClientSecret: clientSecret,
Scopes: []string{"user:read:email"},
RedirectURI: redirectURI,
Token: token,
}
c, err := gundyr.NewHelix(cfg)
if err != nil {
log.Fatal(err)
}
email, err := c.GetUserEmail("your-username")
if err != nil {
log.Fatal(err)
}
log.Println(email)
PubSub - Subscribing to Channel Point Redemptions
func handleChannelPoints(event *pubsub.ChannelPointsEvent) {
fmt.Println(event.Redemption.Reward.Title)
}
func main() {
scopes := []string{"channel:read:redemptions"}
config, err := auth.NewUserAuth(clientID, clientSecret, redirectURI, &scopes)
if err != nil {
log.Fatal(err)
}
token, err := auth.RetrieveTokenFile(config, tokenFile)
if err != nil {
log.Fatal(err)
}
client := pubsub.NewClient(userID, token)
client.ListenChannelPoints(handleChannelPoints)
client.Connect()
select {}
}
Contributions
Any and all contributions or bug fixes are appreciated.