我正在尝试从Twitch的API请求一份直播流媒体列表。
首先,我需要检查来自特定Twitch团队的所有streamers,API给了我他们的ID。然后,我需要检查哪些是现在正在运行的。为此,我编写了以下代码:
import requests
import json
from concurrent.futures import ThreadPoolExecutor
response = requests.get("https://api.twitch.tv/kraken/teams/rhynoesports",
headers={'Accept': 'application/vnd.twitchtv.v5+json',
'Client-ID': 'KEY'})
ids = []
with ThreadPoolExecutor(max_workers=5) as executor:
for i in response.json()["users"]:
uid = i["_id"]
ids.append(uid)
parameters = {
"channel": ids
}
response_live = requests.get("https://api.twitch.tv/kraken/streams/",
params=parameters,
headers={'Accept': 'application/vnd.twitchtv.v5+json',
'Client-ID': 'KEY'})
status = []
with ThreadPoolExecutor(max_workers=5) as executor:
for s in response_live.json()["streams"]:
sid = s["channel"]["display_name"]
sviewer = s["viewers"]
sgame = s["preview"]["medium"]
status.append(sid)
status.append(sviewer)
status.append(sgame)
print(status)
对该接口的第一个请求将其附加到ids
中,如下所示:
['151725719', '45737168', '156113210', '89293605', '650627666', '136014647',
'99060924', '246849290', '61610474', '602283265', '204979621', '507115885',
'49251436', '265876002', '155784200']
如何使用存储的ids
作为channel
请求的参数?
发布于 2021-06-20 09:53:23
https://api.twitch.tv/helix/streams?user_id=123&user_id=456 230
您可以使用此接口查看流ID是否有负载
您将只获得实时流的返回值。
https://stackoverflow.com/questions/68051858
复制相似问题