I’m developing a python game in which viewers can interact via cutom rewards.
The problem is, I can’t get the rewards back.
I created a token with ‘channel: read: redemptions’ rights.
Here is my code:
import websockets
import json
import asyncio
import random
url = “wss://pubsub-edge.twitch.tv”
loop = asyncio.get_event_loop()
connection = websockets.connect(url, ping_interval=100)
client_id = ‘MYCLIENTID’
channel_id = ‘MYUSERID’
access_token = ‘MYTOKEN’
async def stay():
async with connection as socket:
while ():
ping = json.dumps({
“type”: “PING”})
await socket.send(ping)
res = await socket.recv()
print(res)
await asyncio.sleep(100 + random.randrange(1, 50))
async def listen():
async with connection as socket:
data = json.dumps({
“type”: “LISTEN”,
“data”: {
“topics”: [“channel-points-channel-v1.” + channel_id],
“auth_token”: access_token,
}
})
await socket.send(data)
resp = await socket.recv()
dec_resp = json.loads(resp)
print(dec_resp)
# while(loop.is_running):
async for msg in socket:
pass
loop.create_task(stay())
loop.run_until_complete(listen())
i don’t understand what is wrong !
Could you help me ?
Your Post suggests you are trying to read what points rewards exist.
But your code suggests you are trying to retrieve redemptions (aka Purchases or usage) as they happen instead?
So what are you actually trying to do?
What i want :
When a viewer uses channel point to buy a reward, i need to get the information about wich reward it is to create a special event in my game.
Sorry for my english i’m french
EventSub will let you monitor redemptions created for the rewards created by the same client ID
Subscription Types
PubSub, will return for all redemptions for “custom” rewards, this will not include emote modifications, highlight my message etc
PubSub Guide
OK but it doesn’t work with websockets.
So I have to set up a webhook server to retrieve the data and then process it.
I don’t have the knowledge to do this.
Are there any preconfigured solutions to do this with aws or something ?
I tested on my own channel. It’s working as expected for me.
Not to my knowledge no.
Could you tell me what to change on my current code ?
My solution is in nodeJS as I’m not very python fluent
Is your code returning any errors? Collecting any response at all.
Did you get a response to your Listen request? If so did it return an error?
It’s ok!
If you need the working code :
url = "wss://pubsub-edge.twitch.tv"
loop = asyncio.get_event_loop()
connection = websockets.connect(url, ping_interval=100)
client_id = 'myclientid'
channel_id = 'myuserid'
access_token = 'mytokent '
async def stay():
async with connection as socket:
while ():
ping = json.dumps({
"type": "PING"})
await socket.send(ping)
res = await socket.recv()
print(res)
await asyncio.sleep(100 + random.randrange(1, 50))
async def listen():
async with connection as socket:
data = json.dumps({
"type": "LISTEN",
"data": {
"topics": ["channel.channel_points_custom_reward_redemption.add" + channel_id],
"auth_token": access_token,
}
})
await socket.send(data)
resp = await socket.recv()
dec_resp = json.loads(resp)
print(dec_resp)
# while(loop.is_running):
async for msg in socket:
print(msg)
pass
loop.create_task(stay())
loop.run_until_complete(listen())
So that is to say that it is now working? And you fixed the issue, or is it not working?
system
Closed
March 2, 2021, 1:12pm
12
This topic was automatically closed after 30 days. New replies are no longer allowed.