【发布时间】:2020-06-09 07:32:32
【问题描述】:
我正在尝试获取一个 python 脚本来说明一个 twitch 频道是否是实时的,但无法做到这一点,任何和所有的帮助将不胜感激。
这是我能找到的文档 https://dev.twitch.tv/docs/api/guide
这就是我的 atm,但我不断收到“'set' object has no attribute 'items'”。这是来自“Is There Any Way To Check if a Twitch Stream Is Live Using Python?”的修改代码,但是由于新的 API,它现在已经过时了。
import requests
def checkUser():
API_HEADERS = {
'Client-ID : [client id here from dev portal]',
'Accept : application/vnd.twitchtv.v5+json',
}
url = "https://api.twitch.tv/helix/streams/[streamer here]"
req = requests.Session().get(url, headers=API_HEADERS)
jsondata = req.json()
print(jsondata)
checkUser()
【问题讨论】:
-
api_headers 不是字典,它是一个包含 2 个字符串的集合
标签: python twitch-api