本文整理汇总了Python中spotipy.oauth2方法的典型用法代码示例。如果您正苦于以下问题:Python spotipy.oauth2方法的具体用法?Python spotipy.oauth2怎么用?Python spotipy.oauth2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spotipy
的用法示例。
在下文中一共展示了spotipy.oauth2方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _generate_token
# 需要导入模块: import spotipy [as 别名]
# 或者: from spotipy import oauth2 [as 别名]
def _generate_token(self, client_id, client_secret):
credentials = oauth2.SpotifyClientCredentials(
client_secret=client_secret,
)
token = credentials.get_access_token()
return token
示例2: __init__
# 需要导入模块: import spotipy [as 别名]
# 或者: from spotipy import oauth2 [as 别名]
def __init__(self, client_id=None, client_secret=None):
global masterclient
# `spotipy.Spotify` makes use of `self._session` and would
# result in an error. The below line is a workaround.
self._session = None
credentials_provided = client_id is not None \
and client_secret is not None
valid_input = credentials_provided or masterclient is not None
if not valid_input:
raise SpotifyAuthorizationError(
"You must pass in client_id and client_secret to this method "
"when authenticating for the first time."
)
if masterclient:
logger.debug("Reading cached master Spotify credentials.")
# Use cached client instead of authorizing again
# and thus wasting time.
self.__dict__.update(masterclient.__dict__)
else:
logger.debug("Setting master Spotify credentials.")
credential_manager = oauth2.SpotifyClientCredentials(
client_id=client_id,
client_secret=client_secret
)
super().__init__(client_credentials_manager=credential_manager)
# Cache current client
masterclient = self
示例3: getCredentials
# 需要导入模块: import spotipy [as 别名]
# 或者: from spotipy import oauth2 [as 别名]
def getCredentials(self):
try:
return spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())
except spotipy.oauth2.SpotifyOauthError:
print('Did not find Spotify credentials.')
print('Please visit https://github.com/bjarneo/pytify#credentials for more information.')
sys.exit(1)
# query
示例4: register
# 需要导入模块: import spotipy [as 别名]
# 或者: from spotipy import oauth2 [as 别名]
def register():
client_id = needl.settings["spotify"]["client_id"]
client_secret = needl.settings["spotify"]["client_secret"]
if client_id and client_secret:
os.environ["SPOTIPY_CLIENT_ID"] = client_id
os.environ["SPOTIPY_CLIENT_SECRET"] = client_secret
client_credentials_manager = spotipy.oauth2.SpotifyClientCredentials()
global spotify_client
spotify_client = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
search_interval = needl.settings['spotify']['search_interval']
args = map(int, search_interval.split('..'))
needl.schedule.every(*args).minutes.do(search_artist)
示例5: _load_token
# 需要导入模块: import spotipy [as 别名]
# 或者: from spotipy import oauth2 [as 别名]
def _load_token(self):
try:
import spotipy.oauth2
callback_url = '{}{}'.format(self.hass.config.api.base_url, AUTH_CALLBACK_PATH)
cache = self.config.get(CONF_CACHE_PATH, self.hass.config.path(DEFAULT_CACHE_PATH))
self.oauth = spotipy.oauth2.SpotifyOAuth(
self.config.get(CONF_CLIENT_ID), self.config.get(CONF_CLIENT_SECRET),
callback_url, scope=SCOPE,
cache_path=cache)
self.token_info = self.oauth.get_cached_token()
except Exception as e:
LOGGER.error("Could not refresh token")
LOGGER.error(e)