获得使用Spotipy for Python3修改Spotify播放列表的授权 [英] Gaining authorization to modify Spotify playlists using spotipy for Python3

查看:254
本文介绍了获得使用Spotipy for Python3修改Spotify播放列表的授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用python3模块spotipy来访问和编辑我的个人Spotify高级帐户.我已经按照 https://github.com/plamere上的教程进行操作/spotipy/blob/master/docs/index.rst 使用util.prompt_for_user_token方法,直接输入必要的参数(用户名,客户端ID,机密ID,作用域和重定向uri).到目前为止,一切似乎都很好.我的代码(出于安全原因,用户名,客户端ID和客户端机密的填充物):
代码

I'm currently attempting to use spotipy, a python3 module, to access and edit my personal Spotify premium account. I've followed the tutorial on https://github.com/plamere/spotipy/blob/master/docs/index.rst using the util.prompt_for_user_token method by entering the necessary parameters directly (username, client ID, secret ID, scope and redirect uri). Everything seems to be fine up to this part. My code (fillers for username, client id and client secret for security reasons) :
code

它将打开我的默认Web浏览器,并使用其中的代码将我重定向到我的重定向URL.此时,我将复制并粘贴重定向URL(根据提示),然后按Enter.它返回以下错误:

It opens up my default web browser and redirects me to my redirect url with the code in it. At this point, I copy and paste the redirect url (as prompted) and hit enter. It returns the following error:

错误

对于此特定示例,我的重定向uri是" http://google.com/".但是,我尝试了多个重定向uri,但它们似乎都对我产生了相同的错误. (是的,我确实将重定向uri设置为应用程序的空白).我花了几个小时来尝试解决此问题,方法是看在线教程,尝试不同的重定向URL,更改我的代码,但尚未取得任何进展.我希望我只是在这里忽略了一个简单的错误!感谢您提供有关如何解决此问题的反馈!

My redirect uri is 'http://google.com/' for this specific example. However, I've tried multiple redirect uris but they all seem to produce the same error for me. (and yes, I did set my redirect uri as whitespace for my application). I've spent hours trying to fix this issue by looking at online tutorials, trying different redirect urls, changing my code but have yet to make any progress. I'm hoping I am just overlooking a simple mistake here! Any feedback on how to fix this is much appreciated!

如果有关系:我正在使用IDE PyCharm.

If it matters: I'm using the IDE PyCharm.

推荐答案

我认为这是您的重定向URL-适用于我:

I think it is your redirect URL - working for me with:

import os
import spotipy.util as util

# credentials
user = 'username'
desired_scope = 'playlist-modify-private'
id = os.environ.get('SPOT_CLIENT')
secret = os.environ.get('SPOT_SECRET')
uri = 'https://localhost'
token = util.prompt_for_user_token(username=user,
                                   scope=desired_scope,
                                   client_id=id,
                                   client_secret=secret,
                                   redirect_uri=uri)

我认为,对于您的重定向URL,Spotify需要初始的http(s)部分-不要忘记将其也添加到您的Spotify for Developers应用程序的白名单中,否则您将获得"invalid-redirect-uri"

I think for your redirect url spotify requires the initial http(s) part - don't forget to add it to the white-list in your Spotify for Developers app too, as otherwise you will get 'invalid-redirect-uri'.

这篇关于获得使用Spotipy for Python3修改Spotify播放列表的授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆