找不到通过requests.py获取Twitch API信息的方法

问题描述

我被这个 API 困住了。我想打印传入的 json 文件(特定于通道点),但它只是以 html 格式打印整个页面。这是我的代码

import requests
import json

client_id = secret
oauth_token = secret

my_uri = 'https://localhost'

header = {"Authorization": f"Bearer {oauth_token}"}

url = f'https://id.twitch.tv/oauth2/authorize?client_id={client_id}&redirect_uri={my_uri}&response_type=id_token&scope=channel:read:redemptions+openid&state=c3ab8aa609ea11e793ae92361f002671&claims={"id_token":{"email_verified":null}}'

response = requests.get(url,headers=header)

print(response.text)

我的假设是 urlheader 是问题所在。 twitch API 最初是为 c# 或 js 制作的,但我不知道如何将这些信息转换为 python。

我还想知道如何做 Twitch 在 API 中写的“PING”和“PONG”事情

解决方法

response.text 显示 html 文本

response.json 显示 json

告诉我现在是否有效