生成访问令牌 - OAuth2.0

发布于 2025-01-10 12:53:56 字数 992 浏览 0 评论 0原文

我正在使用 Spotify API。我正在尝试生成访问令牌。我跟着https://www.youtube.com/watch?v=xdq6Gz33khQ该视频来生成令牌。

我收到错误

{'error': 'invalid_client'}

我编写的代码是:

import base64
from wsgiref import headers
import requests
import json  

client_id = "09e0b9beeba74aee986546f496823d60"
client_secret = "be1c93f2a446477e8416235b2a3f442c"


# searching for token which will help in authorization

client_creds = f"{client_id} : {client_secret}"

client_creds_b64 = base64.b64encode(client_creds.encode())

token_url = "https://accounts.spotify.com/api/token"
method = "POST"
token_data = {
    "grant_type": "client_credentials"
}

token_header = { 
"Authorization" : f"Basic {client_creds}" # <base64 encoded client_id:client_secret>
}

r = requests.post(token_url, data=token_data, headers=token_header)
print(r.json())

不确定为什么收到此错误。它可能是我用于令牌 URL 的链接,但找不到替换它的内容。

I am working with the Spotify API. I am trying to generate an access token. I followed along https://www.youtube.com/watch?v=xdq6Gz33khQ this video to generate the token.

I am getting an error

{'error': 'invalid_client'}

The code I have written is:

import base64
from wsgiref import headers
import requests
import json  

client_id = "09e0b9beeba74aee986546f496823d60"
client_secret = "be1c93f2a446477e8416235b2a3f442c"


# searching for token which will help in authorization

client_creds = f"{client_id} : {client_secret}"

client_creds_b64 = base64.b64encode(client_creds.encode())

token_url = "https://accounts.spotify.com/api/token"
method = "POST"
token_data = {
    "grant_type": "client_credentials"
}

token_header = { 
"Authorization" : f"Basic {client_creds}" # <base64 encoded client_id:client_secret>
}

r = requests.post(token_url, data=token_data, headers=token_header)
print(r.json())

Not sure why I get this error. It could be the link I am using for the token url but can't find what to replace it with.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月苍老的讽刺 2025-01-17 12:53:56

更改

client_creds = f"{client_id} : {client_secret}"

client_creds = f"{client_id}:{client_secret}"

更改

"Authorization" : f"Basic {client_creds}" # <base64 encoded client_id:client_secret>

"Authorization": f"Basic {client_creds_b64.decode()}"

change

client_creds = f"{client_id} : {client_secret}"

to

client_creds = f"{client_id}:{client_secret}"

change

"Authorization" : f"Basic {client_creds}" # <base64 encoded client_id:client_secret>

to

"Authorization": f"Basic {client_creds_b64.decode()}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文