到目前为止这是我的代码
import requests, json
API_ENDPOINT = 'https://discord.com/api/v8'
CLIENT_ID = '82'
CLIENT_SECRET = 'db'
REDIRECT_URI = 'https://google.com'
def refresh_token(refresh_token):
data = {
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'grant_type': 'refresh_token',
'refresh_token': refresh_token
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
r = requests.post('%s/oauth2/token' % API_ENDPOINT, data=data, headers=headers)
r.raise_for_status()
return r.json()
js = json.loads(open("token.json", "r").read())
for i in js:
js[i] = refresh_token(js[i]["refresh_token"])
open("token.txt", "w").write(json.dumps(js))
每次运行都会报400错误
Traceback (most recent call last):
js[i] = refresh_token(js[i]["refresh_token"])
File "c:\Users\c\Downloads\discord-oauth2-example-master\discord-oauth2-example-master\refresh.py", line 18, in refresh_token
r.raise_for_status()
File "C:\Users\c\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\models.py", line 943, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://discord.com/api/v8/oauth2/token
代码直接取自discord网站,所以我不知道出了什么问题。我的原始令牌赠款正在起作用,但不是这样。有任何想法吗? 谢谢