我正在尝试使用 Spotify API,它需要客户端凭据。我已经集成了spotipy,当我不需要请求用户信息(即只需从艺术家那里下载轨道名称)但我希望访问音频功能时,它工作得很好。
在什么文件/脚本中以及如何包含凭据?
这是他们在 oauth2.py 文件中所说的:
You can either provid a client_id and client_secret to the
constructor or set SPOTIPY_CLIENT_ID and SPOTIPY_CLIENT_SECRET
environment variables
https://github.com/plamere/spotipy/blob/master/examples/audio_features.py
最佳答案
我会开始here - Authorized Requests 。那么你可以简单地使用这个例子:
token = util.prompt_for_user_token(username)
if token:
sp = spotipy.Spotify(auth=token)
开始工作,然后获取您需要的东西。
关于python - 我应该将 API 凭证的环境变量放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40499249/