How to use the spotipy.oauth2 function in spotipy

To help you get started, we’ve selected a few spotipy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thisisayush / stacksfx / portal / utils.py View on Github external
def generate_spotify_token():
    credentials = oauth2.SpotifyClientCredentials(
        client_id='4fe3fecfe5334023a1472516cc99d805',
        client_secret='0f02b7c483c04257984695007a4a8d5c')
    token = credentials.get_access_token()

    return token
github mps-youtube / mps-youtube / mps_youtube / commands / spotify_playlist.py View on Github external
def generate_credentials():
    """Generate the token. Please respect these credentials :)"""
    credentials = oauth2.SpotifyClientCredentials(
        client_id='6451e12933bb49ed8543d41e3296a88d',
        client_secret='40ef54678fe441bd9acd66f5d5c34e69')
    return credentials
github kodi-community-addons / plugin.audio.spotify / resources / lib / utils.py View on Github external
def request_token_web(force=False):
    '''request the (initial) auth token by webbrowser'''
    import spotipy
    from spotipy import oauth2
    xbmcvfs.mkdir("special://profile/addon_data/%s/" % ADDON_ID)
    cache_path = "special://profile/addon_data/%s/spotipy.cache" % ADDON_ID
    cache_path = xbmc.translatePath(cache_path).decode("utf-8")
    scope = " ".join(SCOPE)
    redirect_url = 'http://localhost:%s/callback' % PROXY_PORT
    sp_oauth = oauth2.SpotifyOAuth(CLIENTID, CLIENT_SECRET, redirect_url, scope=scope, cache_path=cache_path)
    # get token from cache
    token_info = sp_oauth.get_cached_token()
    if not token_info or force:
        # request token by using the webbrowser
        p = None
        auth_url = sp_oauth.get_authorize_url()

        # show message to user that the browser is going to be launched
        dialog = xbmcgui.Dialog()
        header = xbmc.getInfoLabel("System.AddonTitle(%s)" % ADDON_ID).decode("utf-8")
        msg = xbmc.getInfoLabel("$ADDON[%s 11049]" % ADDON_ID).decode("utf-8")
        dialog.ok(header, msg)
        del dialog

        if xbmc.getCondVisibility("System.Platform.Android"):
            # for android we just launch the default android browser
github shivasiddharth / GassistPi / src / actions.py View on Github external
Domoticz_Device_Control=False

Spotify_credentials=False
Youtube_credentials=False
if configuration['Spotify']['client_id']!= 'ENTER YOUR SPOTIFY CLIENT ID HERE' and configuration['Spotify']['client_secret']!='ENTER YOUR SPOTIFY CLIENT SECRET HERE':
    Spotify_credentials=True
if configuration['Google_cloud_api_key']!='ENTER-YOUR-GOOGLE-CLOUD-API-KEY-HERE':
    Youtube_credentials=True

# Spotify Declarations
# Register with spotify for a developer account to get client-id and client-secret
if Spotify_credentials:
    client_id = configuration['Spotify']['client_id']
    client_secret = configuration['Spotify']['client_secret']
    username=configuration['Spotify']['username']
    credentials = oauth2.SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)
    spotify_token = credentials.get_access_token()


#Import VLC player
vlcplayer=mediaplayer.vlcplayer()



#Google Music Declarations
song_ids=[]
track_ids=[]


#Login with default kodi/kodi credentials
#kodi = Kodi("http://localhost:8080/jsonrpc")
github resident-archive / resident-archive / ra-tracks / to-playlists / token_gen.py View on Github external
def handler(event, context):
    scope = 'playlist-read-private playlist-modify-private'
    user = '11111204'

    sp_oauth = oauth2.SpotifyOAuth(
            SPOTIPY_CLIENT_ID,
            SPOTIPY_CLIENT_SECRET,
            SPOTIPY_REDIRECT_URI,
            scope=scope,
            cache_path='.cache-'+user
        )
    auth_url = sp_oauth.get_authorize_url()
    subprocess.call(["open", auth_url])
github nithinphilips / spotifyscrape / spotifyscrape / spotipyutil.py View on Github external
sys.stderr.write('''
            You need to set your Spotify API credentials. You can do this by
            setting environment variables like so:

            export SPOTIPY_CLIENT_ID='your-spotify-client-id'
            export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'
            export SPOTIPY_REDIRECT_URI='your-app-redirect-url'

            Get your credentials at
                https://developer.spotify.com/my-applications
        ''')
        raise spotipy.SpotifyException(550, -1, 'no credentials set')

    cache_path = os.path.join(TOKEN_CACHE_PATH, ".cache-" + username)

    sp_oauth = oauth2.SpotifyOAuth(
        client_id, client_secret, redirect_uri,
        scope=scope, cache_path=cache_path
    )

    # try to get a valid token for this user, from the cache,
    # if not in the cache, the create a new (this will send
    # the user to a web page where they can authorize this app)

    token_info = sp_oauth.get_cached_token()

    if not token_info:
        sys.stderr.write('''

            User authentication requires interaction with your
            web browser. Once you enter your credentials and
            give authorization, you will be redirected to
github resident-archive / resident-archive / functions / to-spotify / main.py View on Github external
def get_spotify():
    restore_spotify_token()

    sp_oauth = oauth2.SpotifyOAuth(
            SPOTIPY_CLIENT_ID,
            SPOTIPY_CLIENT_SECRET,
            SPOTIPY_REDIRECT_URI,
            scope=scope,
            cache_path='/tmp/.cache-'+SPOTIPY_USER
        )
    token_info = sp_oauth.get_cached_token()
    if not token_info:
        raise(Exception('null token_info'))
    store_spotify_token(token_info)

    return spotipy.Spotify(auth=token_info['access_token'])
github listen-now / listen-now / project / Scrawl / spotifyMusic / SpotifyMusic.py View on Github external
AUTH_URL = "{}/?{}".format(SPOTIFY_AUTH_URL, URL_ARGS)
#常量

class Spotify(object):
    pre_drivers = []                     #待使用的驱动
    pre_drivers_lock = threading.Lock()  #待使用的驱动锁
    used_drivers = {}                    #已使用驱动
    used_drivers_lock = threading.Lock() #已使用驱动锁
    img_urls = {}                        #9 或 8张图片时每个图片的url 用户名:图片url列表
    state_user = {}                      #用户与 state 的绑定
    user_access_token = {}               #用户 access_token
    user_refresh_token = {}              #用户 refresh_token
    user_login = {}                      #用户的登陆状态

    credentials = oauth2.SpotifyClientCredentials(
        client_id=CLIENT_ID,
        client_secret=CLIENT_SECRET)  #要生成token的东西
    spot = spotipy.Spotify(auth=credentials.get_access_token())
    token = ''


    '''
        :param d_num: 驱动的数量
        初始化几个待用的驱动为了防止token过期 每3分钟删一个
    '''
    def __init__(self, d_num):
        loadd = threading.Thread(target=self.load_driver, args=[d_num])
        loadd.start()
        removet = threading.Thread(target=self.remove_driver)
        removet.start()
        loadt = threading.Thread(target=self.load_token)
github sheagcraig / yaypis / examples / actually_random / actually_random.py View on Github external
def get_oauth():
    """Return a Spotipy Oauth2 object."""
    prefs = get_prefs()
    return spotipy.oauth2.SpotifyOAuth(
        prefs["ClientID"], prefs["ClientSecret"], REDIRECT_URI, scope=SCOPE,
        cache_path=".tokens")