gpt4 book ai didi

python - 有什么方法可以使用 Python 检查 Twitch 流是否在线?

转载 作者:太空狗 更新时间:2023-10-30 00:30:18 24 4
gpt4 key购买 nike

我只是想知道是否有任何方法可以编写 python 脚本来检查 twitch.tv 流是否直播?

我不确定为什么我的应用引擎标签被删除了,但这将使用应用引擎。

最佳答案

由于截至 2020-05-02 所有答案实际上都已过时,我会试一试。您现在需要注册开发人员应用程序(我相信),现在您必须使用需要用户 ID 而不是用户名(因为它们可以更改)的端点。

参见 https://dev.twitch.tv/docs/v5/reference/users

https://dev.twitch.tv/docs/v5/reference/streams

首先,您需要 Register an application

从那里你需要得到你的 Client-ID

这个例子中的那个不是真实的

TWITCH_STREAM_API_ENDPOINT_V5 = "https://api.twitch.tv/kraken/streams/{}"

API_HEADERS = {
'Client-ID' : 'tqanfnani3tygk9a9esl8conhnaz6wj',
'Accept' : 'application/vnd.twitchtv.v5+json',
}

reqSession = requests.Session()

def checkUser(userID): #returns true if online, false if not
url = TWITCH_STREAM_API_ENDPOINT_V5.format(userID)

try:
req = reqSession.get(url, headers=API_HEADERS)
jsondata = req.json()
if 'stream' in jsondata:
if jsondata['stream'] is not None: #stream is online
return True
else:
return False
except Exception as e:
print("Error checking user: ", e)
return False

关于python - 有什么方法可以使用 Python 检查 Twitch 流是否在线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12064130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com