I cant get the user id by the stream id

def obtener_usuario_por_stream(stream_id, client_id):
url = f"https://api.twitch.tv/helix/streams/{stream_id}"
headers = {
“Client-ID”: client_id
}

try:
    
    respuesta = requests.get(url, headers=headers, timeout=10)
    
    respuesta.raise_for_status()
    
    datos = respuesta.json()
    
    if datos["data"]:
        return datos["data"][0]["user_id"]
    else:
        
        return None
except requests.exceptions.RequestException as e:
    raise SystemExit(f"Error al obtener el usuario: {e}")

this is my code in python im new in this and i don know how i can to obtain the streamer by the streaming that he is doing

This is not a valid URL

Get Streams doesn’t have a route for appending a stream ID

Then how can I obtain the streamer through their stream? Thank you for your response

What do you mean “through their stream”

if you call https://api.twitch.tv/helix/streams with no other params

It’ll give you the top streams on the platform by view count.

That’ll contain an example payload such as

    {
      "id": "123456789",
      "user_id": "98765",
      "user_login": "sandysanderman",
      "user_name": "SandySanderman",
      "game_id": "494131",
      "game_name": "Little Nightmares",
      "type": "live",
      "title": "hablamos y le damos a Little Nightmares 1",
      "tags": ["Español"],
      "viewer_count": 78365,
      "started_at": "2021-03-10T15:04:21Z",
      "language": "es",
      "thumbnail_url": "https://static-cdn.jtvnw.net/previews-ttv/live_user_auronplay-{width}x{height}.jpg",
      "tag_ids": [],
      "is_mature": false
    }

This is a stream from sandysanderman

If you have the username or ID of a user on Twitch then you can do

https://api.twitch.tv/helix/streams?user_id=26610234
or
https://api.twitch.tv/helix/streams?user_login=cohhcarnage

Which will both return

{
  "data": [
    {
      "game_id": "515024",
      "game_name": "Diablo IV",
      "id": "41451793625",
      "is_mature": false,
      "language": "en",
      "started_at": "2023-06-07T11:56:03Z",
      "tag_ids": [],
      "tags": [
        "adhd",
        "moderated",
        "devswelcome",
        "parent",
        "goodvibes",
        "chill",
        "BackseatingWelcome",
        "NoPolitics",
        "NoSpoilers",
        "Variety"
      ],
      "thumbnail_url": "https://static-cdn.jtvnw.net/previews-ttv/live_user_cohhcarnage-{width}x{height}.jpg",
      "title": "[!Plushie - LAST DAY!] - Diablo 4 (!Drops \u0026 !GiftSubs) - SGF \u0026 Amnesia later! - !D4Thoughts - !PowerGPU / !MobileApp",
      "type": "live",
      "user_id": "26610234",
      "user_login": "cohhcarnage",
      "user_name": "CohhCarnage",
      "viewer_count": 14439
    }
  ]
}
1 Like

Thanks, man. Looking at those JSON, I can resolve my problem. <3

Sorry one more question. If i have the stream can i look for the user_id of the streamer. Sorry for my english lvl btw

image

1 Like

Thanks again

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