首页 > 解决方案 > 通过 Streamer 获取 Twitch VOD ID 列表

问题描述

我想知道是否有一个 Twitch 应用程序/网站可以为我提供指定 Twitch 频道存在的过去广播的所有 vod ID 的列表。我使用 ReChat 下载聊天日志,这样当我不记得它们发生在哪个流上时,我可以从过去的流中搜索我想重新访问的时刻,但是我发现一个接一个地复制和粘贴每个 VOD ID 很乏味。

我自己不是开发人员,但我知道 JSON API 中有一些东西使这成为可能——只是不知道如何使用它,所以我想知道是否有人在 Internet 上的任何地方设置了它。感谢大家的帮助!

标签: jsonapitwitch

解决方案


所以这花了我太长时间才弄清楚,我仍然不知道如何为使用您的应用程序的用户进行正确的 url 重定向身份验证,但是如果您只想要一个本地或服务器到服务器的 python 脚本,那么这里是如何做它与“新的抽搐 api”。希望它可以帮助那里的人。

import requests
import json

## Its the name you see when you browse to the twitch url of the streamer
USER_ID = "<USER_ID_NAME_YOU_WANT_THE_VIDEOS_FROM>"

## First setup your application on your dashboard.
## here: https://dev.twitch.tv/console
## then click "Register Your Application" on the right hand side.
## For the oauth redirect just write: http://localhost
## Make note of your Client ID
## Make note of your Client Secret 
CLIENT_ID = "<YOUR_CLIENT_ID>" 
SECRET = "<YOUR_CLIENT_SECRET_CODE>"

## First get a local access token. 
secretKeyURL = "https://id.twitch.tv/oauth2/token?client_id={}&client_secret={}&grant_type=client_credentials".format(CLIENT_ID, SECRET)
responseA = requests.post(secretKeyURL)
accessTokenData = responseA.json()

## Then figure out the user id. 
userIDURL = "https://api.twitch.tv/helix/users?login=%s"%USER_ID
responseB = requests.get(userIDURL, headers={"Client-ID":CLIENT_ID,
                                                'Authorization': "Bearer "+accessTokenData["access_token"]})
userID = responseB.json()["data"][0]["id"]


## Now you can request the video clip data.
findVideoURL = "https://api.twitch.tv/helix/videos?user_id=%s"%userID
responseC= requests.get(findVideoURL, headers={"Client-ID":CLIENT_ID,
                                                'Authorization': "Bearer "+accessTokenData["access_token"]})
print ( json.dumps( responseC.json(), indent = 4)  )

推荐阅读