本文整理汇总了Python中spotipy.util方法的典型用法代码示例。如果您正苦于以下问题:Python spotipy.util方法的具体用法?Python spotipy.util怎么用?Python spotipy.util使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spotipy
的用法示例。
在下文中一共展示了spotipy.util方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_new_token
# 需要导入模块: import spotipy [as 别名]
# 或者: from spotipy import util [as 别名]
def get_new_token(self):
token = spotipy.util.prompt_for_user_token(
self.spotify_username,
client_id=self.spotify_client_id,
client_secret=self.spotify_client_secret,
redirect_uri=self.spotify_redirect_uri,
scope="playlist-read-private user-library-read",
)
return token
示例2: getToken
# 需要导入模块: import spotipy [as 别名]
# 或者: from spotipy import util [as 别名]
def getToken(self):
try:
token = util.prompt_for_user_token(self.username, 'playlist-modify-public', self.client_id, self.client_secret, self.redirect)
except:
# os.remove(f".cache-{username}")
token = util.prompt_for_user_token(self.username, 'playlist-modify-public', self.client_id, self.client_secret, self.redirect)
return token
示例3: spotify_client
# 需要导入模块: import spotipy [as 别名]
# 或者: from spotipy import util [as 别名]
def spotify_client(bot):
"""Spotify access requires user authorization. The refresh token is stored
in memory to circumvent logging in after the initial authorization."""
try:
spotify_client_id = bot.config.get_by_path(
["spotify", "spotify", "client_id"])
spotify_client_secret = bot.config.get_by_path(
["spotify", "spotify", "client_secret"])
spotify_redirect_uri = bot.config.get_by_path(
["spotify", "spotify", "redirect_uri"])
spotify_user = bot.config.get_by_path(["spotify", "spotify", "user"])
except (KeyError, TypeError) as e:
logger.error("<b>Spotify authorization isn't configured:</b> {}"
.format(e))
return None
if bot.memory.exists(["spotify", "token"]):
old_spotify_token = bot.memory.get_by_path(["spotify", "token"])
else:
old_spotify_token = ""
spotify_token = spotipy.util.prompt_for_user_token(
spotify_user,
scope="playlist-modify-public playlist-modify-private",
client_id=spotify_client_id,
client_secret=spotify_client_secret,
redirect_uri=spotify_redirect_uri)
if old_spotify_token and old_spotify_token != spotify_token:
bot.memory.set_by_path(["spotify", "token"], spotify_token)
return spotipy.Spotify(auth=spotify_token)
示例4: _get_auth_spotify
# 需要导入模块: import spotipy [as 别名]
# 或者: from spotipy import util [as 别名]
def _get_auth_spotify(user):
# deprecated
global auth_sp
if auth_sp == None:
scope = 'playlist-modify-public playlist-modify-private'
token = spotipy.util.prompt_for_user_token(user, scope)
if token:
auth_sp = spotipy.Spotify(auth=token)
return auth_sp