尝试获得使用youtube API的授权,第一个身份验证请求可以正常工作,但是每当我尝试将访问令牌的授权代码交换时,都会出现如下所示的400错误。
Token Response: {
"error": "invalid_grant",
"error_description": "Bad Request"
}
为获得此结果而调用的URL(已修改):
https://oauth2.googleapis.com/token?code=4/wQHX8O_ckUl3tSkhESEWuzOy_VhbGnTkpz-uE98FpzVhLxjA&client_id=80816cq3laikjocnu2imtqj7hhfdnu7jfih4l.apps.googleusercontent.com&client_secret=ZLuIRNEF&grant_type=authorization_code&redirect_uri=http%3A//127.0.0.1%3A49669&code_verifier=jaksfoiasjevtomiiszjfkldfsajmvsifhjavsmlkdfjasclmjhvsdajnhfvadxjkh
生成URL的代码:
def url_squisher(url_components):
i = 0
url = ""
for x in url_components:
url += "".join(x)
if i > 1 and i % 2 == 0:
url += "&"
elif i == 0:
url += "?"
i += 1
urllib.parse.quote(url)
url = url[:len(url)-1]
return url
生成用于调用Auth请求的URL很好,但是如果令牌请求中出现问题,则可以idk。
以下是调用URL的代码:
def get_token():
code = get_auth()
endpoint = "https://oauth2.googleapis.com/token"
token_request = [endpoint, "code=", code, "client_id=", client_id, "client_secret=", client_secret, "grant_type=",
"authorization_code", "redirect_uri=", redirect_uri, "code_verifier=", code_verifier]
tokenurl = url_squisher(token_request)
print(tokenurl)
tokenresponse = requests.post(tokenurl)
print("Token Response:", tokenresponse.text)
我已经尝试过更改计算机时钟以匹配其他Web服务器的技巧,但对我来说不起作用。