Twitch:客户端ID和OAuth令牌不匹配



我正试图使一个不和谐的机器人发送通知,如果一个特定的流是活在一个特定的词在标题。当我试图运行代码时,我得到了以下错误:

{'error': 'Unauthorized', 'status': 401, 'message': 'Client ID and OAuth token do not match'}

代码如下:

import discord
import requests
import asyncio
intents = discord.Intents.default()
intents.guilds = True
intents.guild_messages = True
client = discord.Client(intents=intents)
client_id = 'CLIENT_ID'
access_token = 'ACCESS_TOKEN'
streamer_id = 'STREAMER_ID'
@client.event
async def on_ready():
client.loop.create_task(run_stream_check())
async def check_stream():
headers = {
'Client-ID': client_id,
'Authorization': f'Bearer {access_token}'
}
url = f'https://api.twitch.tv/helix/streams?user_id={streamer_id}'
response = requests.get(url, headers=headers)
print(response.json())
data = response.json()
if 'data' in data:
if data['data']:
if 'TEST' in data['data'][0]['title']:
channel = client.get_channel(1057814763087872212)
await channel.send('Streamer is live with TEST in the title')
async def run_stream_check():
while True:
await check_stream()
await asyncio.sleep(300)
client.run('DISCORD_BOT_TOKEN')

我显然替换了python文件中的占位符。

我检查了我的客户端id,访问令牌和bot令牌是否正确。我还试图检查我的访问令牌是否与"curl"在那里它工作得很好。

headers = {
'Client-ID': client_id,
'Authorization': f'Bearer {access_token}'
}

那么这段代码中的client_id不是用来创建access_tokenclient_id

或者您实际上使用了您的客户端密钥而不是生成令牌来使用

最新更新