它只是说 {“error”:“Unauthorized”,“status”:401,“message”:“获取授权令牌时出错”} ,不知道为什么我可以写与我的令牌聊天。 这是代码:
url = "https://api.twitch.tv/kraken/channel"
channel_id = urllib.request.Request(url)
channel_id.add_header("Client-ID", CLIENT_ID)
#MY_OAUTH defined as MY_OAUTH = "oauth:123blablabla"
channel_id.add_header("Authorization: OAuth", MY_OAUTH")
response = urllib.request.urlopen(channel_id)
tmpJSON = json.loads(response.read())
编辑:这是get_channel_id函数的Pastebin:https://pastebin.com/Jm0EuWk9
答案 0 :(得分:0)
您的Authorization
标头似乎格式不正确。假设MY_OAUTH
作为您的访问令牌,我相信您的意思是写:
channel_id.add_header("Authorization", "OAuth " + MY_OAUTH)
实际上,Twitch-API authentication documentation建议在HTTP标头中传递访问令牌时执行以下请求:
curl -H "Authorization: OAuth [access token]" https://api.twitch.tv/kraken/
如您所见,标题需要设为Authorization: OAuth [access token]
,而不是Authorization: OAuth: [access token]
。