# Pubsub subscriber / resubscriber example

**URL:** <https://discuss.dev.twitch.com/t/pubsub-subscriber-resubscriber-example/17075>\
**Category:** API\
**Created:** [August 11, 2018, 7:32am UTC](https://discuss.dev.twitch.com/t/pubsub-subscriber-resubscriber-example/17075 "2018-08-11T07:32:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lilrex](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/lilrex/32/4782_2.png) [@Lilrex](https://discuss.dev.twitch.com/u/Lilrex)\
**Post date:** [August 11, 2018, 7:32am UTC](https://discuss.dev.twitch.com/t/pubsub-subscriber-resubscriber-example/17075/1 "2018-08-11T07:32:18Z")

</div>

Does anyone have an example of how to use the Twitch PubSub to track information like subscribers and resubs? I already looked at the Twitch Github ([[https://github.com/twitchdev/pubsub-samples/blob/master/javascript/index.html](https://github.com/twitchdev/pubsub-samples/blob/master/javascript/index.html)] example code but am still pretty lost on how to properly use this.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [August 11, 2018, 10:06am UTC](https://discuss.dev.twitch.com/t/pubsub-subscriber-resubscriber-example/17075/2 "2018-08-11T10:06:38Z")

</div>

Pubsub requires you to setup a listener.

That listener connects to Twitch Pubsub server.  
It then requests topics  
Then Twitch will send you events for those topics when they occur.

So when you say

> [@Lilrex](#):
>
> example code but am still pretty lost on how to properly use this.

What do you mean? What do you want to do?

---

<div class="post-metadata">

**Author:** ![Lilrex](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/lilrex/32/4782_2.png) [@Lilrex](https://discuss.dev.twitch.com/u/Lilrex)\
**Post date:** [August 11, 2018, 4:33pm UTC](https://discuss.dev.twitch.com/t/pubsub-subscriber-resubscriber-example/17075/3 "2018-08-11T16:33:45Z")

</div>

I want to be able to grab new or re-subscriber events to push notifications.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [August 12, 2018, 10:00am UTC](https://discuss.dev.twitch.com/t/pubsub-subscriber-resubscriber-example/17075/4 "2018-08-12T10:00:07Z")

</div>

Pubsub is documented here:

> **[PubSub](https://dev.twitch.tv/docs/pubsub/)**
>
> PubSub Guide

Pay attention to the `connection management` about ping/pong.

1. Connect to pubsub using language of choice that supports websockets
2. On connect send the `listen` command using the topic `channel-subscribe-events-v1.<channel ID>`
3. Wait for messages and parse them

---

<div class="post-metadata">

**Author:** ![Lilrex](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/lilrex/32/4782_2.png) [@Lilrex](https://discuss.dev.twitch.com/u/Lilrex)\
**Post date:** [August 13, 2018, 4:37am UTC](https://discuss.dev.twitch.com/t/pubsub-subscriber-resubscriber-example/17075/5 "2018-08-13T04:37:29Z")

</div>

kind of a dumb question, but I dont have a partner/affiliate account, how can I test bits and subs? or am i not able to?

---

<div class="post-metadata">

**Author:** ![Dist](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dist/32/7192_2.png) [@Dist](https://discuss.dev.twitch.com/u/Dist)\
**Post date:** [August 13, 2018, 8:53am UTC](https://discuss.dev.twitch.com/t/pubsub-subscriber-resubscriber-example/17075/6 "2018-08-13T08:53:57Z")

</div>

Find someone who is a partner/affiliate and willing to work with you. They’d need to go through your authentication process so you get a token, and you’ll use that with their pubsub topic.

---

<div class="post-metadata">

**Author:** ![Lilrex](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/lilrex/32/4782_2.png) [@Lilrex](https://discuss.dev.twitch.com/u/Lilrex)\
**Post date:** [August 13, 2018, 3:50pm UTC](https://discuss.dev.twitch.com/t/pubsub-subscriber-resubscriber-example/17075/7 "2018-08-13T15:50:44Z")

</div>

damn, thats what i figured was going to have to happen. Thank you.

---

<div class="post-metadata">

**Author:** ![george](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/george/32/120_2.png) [@george](https://discuss.dev.twitch.com/u/george)\
**Post date:** [August 13, 2018, 4:16pm UTC](https://discuss.dev.twitch.com/t/pubsub-subscriber-resubscriber-example/17075/8 "2018-08-13T16:16:49Z")

</div>

Stream yourself developing the application. You might get enough viewers to earn affiliate. 😀

---

<div class="post-metadata">

**Author:** ![Lilrex](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/lilrex/32/4782_2.png) [@Lilrex](https://discuss.dev.twitch.com/u/Lilrex)\
**Post date:** [August 13, 2018, 4:19pm UTC](https://discuss.dev.twitch.com/t/pubsub-subscriber-resubscriber-example/17075/9 "2018-08-13T16:19:10Z")

</div>

oh, haha, i appreciate that, i actually qualified for affiliate a long time ago, I just never accepted bc of the exclusivity clause (2.2 or 2.4) I like multi-streaming, But i do appreciate the suggestion, thank you.

---

<div class="post-metadata">

**Author:** ![Lilrex](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/lilrex/32/4782_2.png) [@Lilrex](https://discuss.dev.twitch.com/u/Lilrex)\
**Post date:** [August 13, 2018, 7:50pm UTC](https://discuss.dev.twitch.com/t/pubsub-subscriber-resubscriber-example/17075/10 "2018-08-13T19:50:16Z")

</div>

is there a way to spoof an Event? I am still new to the whole pubsub thing, so forgive me if thats a dumb question.

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [September 12, 2018, 7:50pm UTC](https://discuss.dev.twitch.com/t/pubsub-subscriber-resubscriber-example/17075/11 "2018-09-12T19:50:16Z")

</div>

Closed on September 12, 2018, 7:50pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
