當前位置: 首頁>>代碼示例>>Python>>正文


Python spotipy.oauth2方法代碼示例

本文整理匯總了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 
開發者ID:ritiek,項目名稱:spotify-downloader,代碼行數:8,代碼來源:spotify.py

示例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 
開發者ID:ritiek,項目名稱:spotify-downloader,代碼行數:32,代碼來源:spotify.py

示例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 
開發者ID:bjarneo,項目名稱:Pytify,代碼行數:13,代碼來源:pytifylib.py

示例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) 
開發者ID:eth0izzle,項目名稱:Needl,代碼行數:14,代碼來源:spotify.py

示例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) 
開發者ID:macbury,項目名稱:SmartHouse,代碼行數:15,代碼來源:sensor.py


注:本文中的spotipy.oauth2方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。