// Sends a Subscribe Request for Go Live Events for the Provided Users
Sends a Subscribe Request for Go Live Events for the Provided Users
// Sends a Subscribe Request for Go Live Events for the Provided Users
func (t *twitch) SubscribeToStreams(notifyEndPoint string, userIds []string) {
	if len(userIds) == 0 {
		return
	}
	for _, userId := range userIds {
		topicUrl := getStreamTopicUrl(userId)
		payload := TwitchWebhookPayload{
			CallbackUrl:  notifyEndPoint,
			Mode:         TwitchModeSubscribe,
			Topic:        topicUrl,
			LeaseSeconds: TwitchMaxLeaseSeconds,
		}
		jsonBytes, err := httputil.EncodeJson(payload)
		if err != nil {
			log.Fatalln(err)
		}
		request, err := http.NewRequest(http.MethodPost, TwitchWebhookUrl, bytes.NewBuffer(jsonBytes))
		if err != nil {
			log.Fatalln(err)
		}
		request.Header.Set(httputil.HttpContentTypeHeader, httputil.JsonContentType)
		request.Header.Set(httputil.HttpClientIdHeader, t.clientId)
		httpClient := &http.Client{}
		resp, err := httpClient.Do(request)
		if err != nil {
			log.Fatalln(err)
		}
		var result map[string]interface{}
		json.NewDecoder(resp.Body).Decode(&result)
	}
}
func ( t * twitch ) SubscribeToStreams ( notifyEndPoint string , userIds [ ] string ) { if len ( userIds ) == 0 { return } for _ , userId := range userIds { topicUrl := getStreamTopicUrl ( userId ) payload := TwitchWebhookPayload { CallbackUrl : notifyEndPoint , Mode : TwitchModeSubscribe , Topic : topicUrl , LeaseSeconds : TwitchMaxLeaseSeconds , } jsonBytes , err := httputil . EncodeJson ( payload ) if err != nil { log . Fatalln ( err ) } request , err := http . NewRequest ( http . MethodPost , TwitchWebhookUrl , bytes . NewBuffer ( jsonBytes ) ) if err != nil { log . Fatalln ( err ) } request . Header . Set ( httputil . HttpContentTypeHeader , httputil . JsonContentType ) request . Header . Set ( httputil . HttpClientIdHeader , t . clientId ) httpClient := & http . Client { } resp , err := httpClient . Do ( request ) if err != nil { log . Fatalln ( err ) } var result map [ string ] interface { } json . NewDecoder ( resp . Body ) . Decode ( & result ) } }
Sends a Subscribe Request for Go Live Events for the Provided Users
Sends a Subscribe Request for Go Live Events for the Provided Users