Help us shape the future of Go! Take the 2026 Go Developer Survey

twitch

package module
v0.0.0-...-03e7ebb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2018 License: MIT Imports: 9 Imported by: 0

README

Twitch API (Golang)

Travis GitHub issues Coveralls license Beerpay

This is a Go wrapper for the Twitch.tv Kraken API, initially created for an internal project, but am making public as I build it out to our requirements.

Usage
package main

import (
	"fmt"

	"github.com/tserkov/go-twitch-api"
)

func main() {
	t := twitch.NewClient("CLIENT_ID", "CLIENT_SECRET", "CLIENT_REDIRECT")

	u, err := t.Users.GetByLogin("tserkov")

	if err != nil {
		fmt.Printf("Failed to get users: %s", err)

		return
	}

	if u.Total == 0 {
		fmt.Printf("No users found with login/username tserkov")

		return
	}

	tserkov := u.Users[0]

	fmt.Printf("User ID for %s is %s", tserkov.DisplayName, tserkov.Id)
}
Users
  • GetAccessToken (authorizationCode string) string
    • Exchanges an authorization code (which you somehow obtained from Twitch's OAuth flow) for an access token.
  • GetAuthenticated (accessToken string) twitch.User, error
    • Gets the user associated with the provided access token.
  • GetByLogin (username string) twitch.Users, error
    • Returns users matching the provided username/login. Useful for converting username/login to user id.
  • GetFollowedChannelInfo (followerId string, channelId string) twitch.Follows, error
    • If the provided user id is following the provided channel id, returns the related follow info.
Todo
  • Channels endpoints
  • Chat endpoints
  • Games endpoints
  • Ingests endpoints
  • Search endpoints
  • Streams endpoints
  • Teams endpoints
  • Users endpoints
  • Videos endpoints

Yea... all the endpoints.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	BroadcasterLanguage          string      `json:"broadcaster_language"`
	BroadcasterType              string      `json:"broadcaster_type"`
	CreatedAt                    time.Time   `json:"created_at"`
	Description                  string      `json:"description"`
	DisplayName                  string      `json:"display_name"`
	Email                        string      `json:"email"`
	Followers                    int         `json:"followers"`
	Game                         string      `json:"game"`
	ID                           json.Number `json:"_id"`
	Language                     string      `json:"language"`
	Mature                       bool        `json:"mature"`
	Name                         string      `json:"name"`
	ProfileBanner                string      `json:"profile_banner"`
	ProfileBannerBackgroundColor string      `json:"profile_banner_background_color"`
	Partner                      bool        `json:"partner"`
	Status                       string      `json:"status"`
	StreamKey                    string      `json:"stream_key"`
	Url                          string      `json:"url"`
	UpdatedAt                    time.Time   `json:"updated_at"`
	VideoBanner                  string      `json:"video_banner"`
	Views                        int         `json:"views"`
}

type ChannelFollower

type ChannelFollower struct {
	CreatedAt     time.Time `json:"created_at"`
	Notifications bool      `json:"notifications"`
	User          User      `json:"user"`
}

type ChannelFollowers

type ChannelFollowers struct {
	Cursor  string            `json:"_cursor"`
	Follows []ChannelFollower `json:"follows"`
	Total   int               `json:"_total"`
}

type ChannelSubscribersParams

type ChannelSubscribersParams struct {
	Direction int    `json:"direction,omitempty"`
	Limit     string `json:"limit,omitempty"`
	Offset    string `json:"offset,omitempty"`
}

type ChannelSubscription

type ChannelSubscription struct {
	CreatedAt   time.Time `json:"created_at"`
	ID          string    `json:"_id"`
	SubPlan     string    `json:"sub_plan"`
	SubPlanName string    `json:"sub_plan_name"`
	User        User      `json:"user"`
}

type ChannelSubscriptions

type ChannelSubscriptions struct {
	Subscriptions []ChannelSubscription `json:"subscriptions"`
	Total         int                   `json:"_total"`
}

type ChannelTeams

type ChannelTeams struct {
	Teams []Team `json:"teams"`
}

type ChannelUpdateParams

type ChannelUpdateParams struct {
	ChannelFeedEnabled bool   `json:"channel_feed_enabled,omitempty"`
	Game               string `json:"game,omitempty"`
	Delay              int    `json:"delay,omitempty"`
	Status             string `json:"status,omitempty"`
}

type ChannelsService

type ChannelsService struct {
	// contains filtered or unexported fields
}

func (*ChannelsService) CheckChannelSubscriptionByUser

func (s *ChannelsService) CheckChannelSubscriptionByUser(accessToken string, channelID string, userID string) (ChannelSubscription, error)

Checks if a specified channel has a specified user subscribed to it. Required scope: channel_check_subscription

func (*ChannelsService) DeleteChannelFromCommunities

func (s *ChannelsService) DeleteChannelFromCommunities(accessToken string, channelID string) error

Deletes a specified channel from its communities. Required scope: channel_editor

func (*ChannelsService) GetChannel

func (s *ChannelsService) GetChannel(accessToken string) (Channel, error)

Gets a channel object based on a specified OAuth token Returns more data than GetChannelByID because this is privileged Required scopes: channel_read

func (*ChannelsService) GetChannelByID

func (s *ChannelsService) GetChannelByID(channelID string) (Channel, error)

Gets a specified channel object Required scopes: none

func (*ChannelsService) GetChannelCommunities

func (s *ChannelsService) GetChannelCommunities(channelID string) (Communities, error)

Gets the communities for a specified channel. Required scope: none

func (*ChannelsService) GetChannelEditors

func (s *ChannelsService) GetChannelEditors(accessToken string, channelID string) (Users, error)

Gets a list of users who are editors for a specified channel Required scopes: channel_read

func (*ChannelsService) GetChannelFollowers

func (s *ChannelsService) GetChannelFollowers(channelID string) (ChannelFollowers, error)

Gets a list of users who follow a specified channel, sorted by the date when they started following the channel, up to 25 at a time Required scopes: none

func (*ChannelsService) GetChannelSubscribers

func (s *ChannelsService) GetChannelSubscribers(accessToken string, channelID string, params *ChannelSubscribersParams) (ChannelSubscriptions, error)

Gets a list of users subscribed to a specific channel, sortedb y the date when the subscribed, up to 25 at a time Required scopes: channel_subscriptions

func (*ChannelsService) GetChannelTeams

func (s *ChannelsService) GetChannelTeams(channelID string) (ChannelTeams, error)

Gets a list of teams to which a specified channel belongs Required scopes: none

func (*ChannelsService) GetChannelVideos

func (s *ChannelsService) GetChannelVideos(channelID string) (Videos, error)

Gets a list of VODs (Video on Demand) from a specified channel. Required scope: none

func (*ChannelsService) ResetChannelStreamKey

func (s *ChannelsService) ResetChannelStreamKey(accessToken string, channelID string) (Channel, error)

Deletes the stream key for a specified channel. Once it is deleted, the stream key is automatically reset. Required scope: channel_stream

func (*ChannelsService) SetChannelCommunities

func (s *ChannelsService) SetChannelCommunities(accessToken string, channelID string, communities []string) error

Sets a specified channel to be in up to three specified communities. The list of community IDs is specified in the body of the request. Required scope: channel_editor

func (*ChannelsService) StartChannelCommercial

func (s *ChannelsService) StartChannelCommercial(accessToken string, channelID string, length int) (CommercialResponse, error)

Starts a commercial (advertisement) on a specified channel. This is valid only for channels that are Twitch partnes. You cannot start a commercial more often than once every 8 minutes. Valid length values: 0, 60, 90, 120, 150, 180 Required scope: channel_commercial

func (*ChannelsService) UpdateChannel

func (s *ChannelsService) UpdateChannel(accessToken string, channelID string, params *ChannelUpdateParams) (Channel, error)

Updates specified properties of a specified channel Required scopes: channel_editor

type CommercialResponse

type CommercialResponse struct {
	Length     int    `json:"Length"`
	Message    string `json:"Message"`
	Retryafter int    `json:"RetryAfter"`
}

type Communities

type Communities struct {
	Communities []Community `json:"communities"`
}

type Community

type Community struct {
	AvatarImageUrl  string `json:"avatar_image_url"`
	CoverImageUrl   string `json:"cover_image_url"`
	Description     string `json:"description"`
	DescriptionHtml string `json:"description_html"`
	DisplayName     string `json:"display_name"`
	ID              string `json:"_id"`
	Language        string `json:"language"`
	Name            string `json:"name"`
	OwnerID         string `json:"owner_id"`
	Rules           string `json:"rules"`
	RulesHtml       string `json:"rules_html"`
	Summary         string `json:"summary"`
}

type Follows

type Follows struct {
	CreatedAt     time.Time `json:"created_id"`
	Notifications bool      `json:"notifications"`
	Channel       Channel
}

type Team

type Team struct {
	Banner      string    `json:"banner"`
	Background  string    `json:"background"`
	CreatedAt   time.Time `json:"created_at"`
	DisplayName string    `json:"display_name"`
	ID          int       `json:"_id"`
	Info        string    `json:"info"`
	Name        string    `json:"name"`
	UpdatedAt   time.Time `json:"updated_at"`
}

type TokenResponse

type TokenResponse struct {
	AccessToken  string   `json:"access_token"`
	RefreshToken string   `json:"refresh_token"`
	Scope        []string `json:"scope"`
}

type TwitchClient

type TwitchClient struct {
	Channels *ChannelsService
	//	Chat       *ChatService
	//	Games      *GamesService
	//	Ingests    *IngestsService
	//	Search     *SearchService
	//	Streams    *StreamsService
	//	Teams      *TeamsService
	Users *UsersService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(clientId, clientSecret, oauthRedirect string) *TwitchClient

type TwitchError

type TwitchError struct {
	Error   string `json:"error"`
	Status  int    `json:"status"`
	Message string `json:"message"`
}

type User

type User struct {
	ID                 string    `json:"_id"`
	Name               string    `json:"name"`
	DisplayName        string    `json:"display_name"`
	Email              string    `json:"email"`
	IsEmailVerified    bool      `json:"email_verified"`
	Bio                string    `json:"bio"`
	IsPartnered        bool      `json:"partnered"`
	IsTwitterConnected bool      `json:"twitter_connected"`
	CreatedAt          time.Time `json:"created_at"`
	UpdatedAt          time.Time `json:"updated_at"`
}

type Users

type Users struct {
	Total int    `json:"_total"`
	Users []User `json:"users"`
}

type UsersService

type UsersService struct {
	// contains filtered or unexported fields
}

func (*UsersService) GetAccessToken

func (u *UsersService) GetAccessToken(code string) (string, error)

func (*UsersService) GetFollowedChannelInfo

func (u *UsersService) GetFollowedChannelInfo(followerId string, channelId string) (Follows, error)

func (*UsersService) GetUser

func (u *UsersService) GetUser(accessToken string) (User, error)

Gets a user object based on the OAuth token provided. Required scopes: user_read

func (*UsersService) GetUserByID

func (u *UsersService) GetUserByID(userID string) (User, error)

Gets a specified user object. Required scopes: none

func (*UsersService) GetUsers

func (u *UsersService) GetUsers(usernames []string) (Users, error)

Gets the user objects for the specified Twitch login names (up to 100). If a specified user’s Twitch-registered email address is not verified, null is returned for that user. Required scopes: none

type Video

type Video struct {
	AnimatedPreviewUrl string           `json:"animated_preview_url"`
	BroadcastID        int              `json:"broadcast_id"`
	BroadcastType      string           `json:"broadcast_type"`
	Communities        string           `json:"communities"`
	CreatedAt          time.Time        `json:"created_at"`
	Channel            Channel          `json:"channel"`
	DescriptionHtml    string           `json:"description_html"`
	Description        string           `json:"description"`
	Fps                VideoFPS         `json:"fps"`
	Game               string           `json:"game"`
	ID                 string           `json:"_id"`
	Language           string           `json:"language"`
	Length             int              `json:"length"`
	Preview            VideoPreviews    `json:"preview"`
	PublishedAt        time.Time        `json:"published_at"`
	RecordedAt         time.Time        `json:"recorded_at"`
	Resolutions        VideoResolutions `json:"resolutions"`
	Status             string           `json:"status"`
	TagList            string           `json:"tag_list"`
	Thumbnails         VideoThumbnails  `json:"thumbnails"`
	Title              string           `json:"title"`
	Url                string           `json:"url"`
	Viewable           string           `json:"viewable"`
	Views              int              `json:"views"`
	ViewableAt         time.Time        `json:"viewable_at"`
}

type VideoFPS

type VideoFPS struct {
	Chunked float32 `json:"chunked"`
	High    float32 `json:"high"`
	Low     float32 `json:"low"`
	Medium  float32 `json:"medium"`
	Mobile  float32 `json:"mobile"`
}

type VideoPreviews

type VideoPreviews struct {
	Large    string `json:"large"`
	Medium   string `json:"medium"`
	Small    string `json:"small"`
	Template string `json:"template"`
}

type VideoResolutions

type VideoResolutions struct {
	Chunked string `json:"chunked"`
	High    string `json:"high"`
	Low     string `json:"low"`
	Medium  string `json:"medium"`
	Mobile  string `json:"mobile"`
}

type VideoThumbnail

type VideoThumbnail struct {
	Type string `json:"type"`
	Url  string `json:"url"`
}

type VideoThumbnails

type VideoThumbnails struct {
	Large    []VideoThumbnail `json:"large"`
	Medium   []VideoThumbnail `json:"medium"`
	Small    []VideoThumbnail `json:"small"`
	Template []VideoThumbnail `json:"template"`
}

type Videos

type Videos struct {
	Total  int     `json:"_total"`
	Videos []Video `json:"videos"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL