当前位置: 首页>>代码示例>>Python>>正文


Python Rdio.complete_authentication方法代码示例

本文整理汇总了Python中rdio.Rdio.complete_authentication方法的典型用法代码示例。如果您正苦于以下问题:Python Rdio.complete_authentication方法的具体用法?Python Rdio.complete_authentication怎么用?Python Rdio.complete_authentication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rdio.Rdio的用法示例。


在下文中一共展示了Rdio.complete_authentication方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: auth

# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import complete_authentication [as 别名]
def auth():
    request_token = session.get('rt')
    request_token_secret = session.get('rts')
    verifier = request.args.get('oauth_verifier', '')
    if request_token and request_token_secret and verifier:
        rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET), (request_token, request_token_secret))
        rdio.complete_authentication(verifier)
        session['at'] = rdio.token[0]
        session['ats'] = rdio.token[1]
        session['rt'] = ''
        session['rts'] = ''
        rdio_data = rdio.call('currentUser', params={'extras': 'username,displayName'})['result']
        username = rdio_data['username']
        print 'Creating user model.'
        user = User.query.filter(User.username == username).first()
        if user is None:
            user = User(username=username, key=rdio_data['key'], icon=rdio_data['icon'], name=rdio_data['displayName'])
            db_session.add(user)
            db_session.commit()
            playlists = rdio.call('getPlaylists', params={'extras': 'tracks,description,isViewable'})['result']['owned']
            #print playlists
            import_new_user_playlists(playlists, user.id)
        print 'Committed.'
        session['user_id'] = user.id
        print session
        return redirect(url_for('main'))
    else:
        # Login failed, clear everything
        print 'Auth failed.'
        logout()
        return redirect(url_for('main'))
开发者ID:nickdirienzo,项目名称:playgit,代码行数:33,代码来源:main.py

示例2: rdio_access_token

# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import complete_authentication [as 别名]
def rdio_access_token(request=None, oauth_temp_db=None):
    '''OAuth dance.'''
    callback_token = request.args.get('oauth_token')
    callback_verifier = request.args.get('oauth_verifier')
    oauth_dance_token = oauth_temp_db.find_one({'oauth token': callback_token}) 
    oauth_dance_token = oauth_dance_token['oauth_dance_token']
    rdio = Rdio((CONSUMER_KEY, CONSUMER_SECRET), oauth_dance_token)
    rdio.complete_authentication(callback_verifier)
    access_token = rdio.token
    return access_token
开发者ID:ecalifornica,项目名称:rdio_playlist,代码行数:12,代码来源:lib.py

示例3: login_callback

# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import complete_authentication [as 别名]
def login_callback():
  params = dict([part.split('=') for part in request.query_string.split('&')])
  token = session['rt']
  secret = session['rts']
  api = Rdio((rdio_key, rdio_secret), (token, secret))
  api.complete_authentication(params.get('oauth_verifier'))
  session['rt'] = None
  session['rts'] = None
  session['at'] = api.token[0]
  session['ats'] = api.token[1]
  return redirect(url_for('index'))
开发者ID:endenizen,项目名称:genredio,代码行数:13,代码来源:web.py

示例4: login_callback

# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import complete_authentication [as 别名]
def login_callback():
    params = dict([part.split("=") for part in request.query_string.split("&")])
    token = session["rt"]
    secret = session["rts"]
    api = Rdio((rdio_key, rdio_secret), (token, secret))
    api.complete_authentication(params.get("oauth_verifier"))
    session["rt"] = None
    session["rts"] = None
    session["at"] = api.token[0]
    session["ats"] = api.token[1]
    return redirect(url_for("index"))
开发者ID:klobucar,项目名称:genredio,代码行数:13,代码来源:web.py

示例5: login

# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import complete_authentication [as 别名]
def login():
    args = request.args
    if 'token' in session and 'oauth_verifier' in args:
        verifier = request.args.get('oauth_verifier')
        rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET), session['token'])
        rdio.complete_authentication(verifier)
        session['token'] = rdio.token
        user = rdio.call('currentUser')['result']
        session['user'] = user['key']
        users[user['key']] = user
        username = rdio.call('currentUser', {'extras': 'username'})['result']['username']
        return redirect(url_for('playlists', username=username))
    rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET))
    auth_url = rdio.begin_authentication(SITE_URL + '/login')
    session['token'] = rdio.token
    return redirect(auth_url)
开发者ID:cvan,项目名称:playlist_builder,代码行数:18,代码来源:app.py

示例6: GET

# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import complete_authentication [as 别名]
 def GET(self):
   # get the state from cookies and the query string
   request_token = web.cookies().get('rt')
   request_token_secret = web.cookies().get('rts')
   verifier = web.input()['oauth_verifier']
   # make sure we have everything we need
   if request_token and request_token_secret and verifier:
     # exchange the verifier and request token for an access token
     rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET),
       (request_token, request_token_secret))
     rdio.complete_authentication(verifier)
     # save the access token in cookies (and discard the request token)
     web.setcookie('at', rdio.token[0], expires=60*60*24*14) # expires in two weeks
     web.setcookie('ats', rdio.token[1], expires=60*60*24*14) # expires in two weeks
     web.setcookie('rt', '', expires=-1)
     web.setcookie('rts', '', expires=-1)
     # go to the home page
     raise web.seeother('/')
   else:
     # we're missing something important
     raise web.seeother('/logout')
开发者ID:ColdSauce,项目名称:rdio-simple,代码行数:23,代码来源:web-based.py

示例7: callback

# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import complete_authentication [as 别名]
def callback():
    request_token = session['rt']
    request_token_secret = session['rts']
    verifier = request.args["oauth_verifier"]
    
    # make sure we have everything we need
    if request_token and request_token_secret and verifier:
        # exchange the verifier and request token for an access token
        rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET), (request_token, request_token_secret))
        rdio.complete_authentication(verifier)
        # save the access token in cookies (and discard the request token)
        session['at'] = rdio.token[0]
        session['ats'] = rdio.token[1]
        session['rt'] = ''
        session['rts'] = ''

        # go to the home page
        return redirect(url_for('home'))
    else:
        # we're missing something important
        return redirect(url_for('logout'))
开发者ID:brettjurgens,项目名称:voicedio,代码行数:23,代码来源:voicedio.py

示例8: callback

# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import complete_authentication [as 别名]
def callback():
    app.logger.info('yayyyyyy')
    #get the state from cookies and the query string
    request_token = request.cookies.get('rt')
    request_token_secret = request.cookies.get('rts')
    verifier = request.args['oauth_verifier']
    print(request_token+'rts'+request_token_secret+'verifer'+verifier)
    #make sure we have everything we need
    if request_token and request_token_secret and verifier:
        rdio = Rdio(RDIO_CREDENTIALS, (request_token, request_token_secret))
        rdio.complete_authentication(verifier)
        print('blah'+rdio.token)
        redirect_to_home = redirect('/')
        response = make_response(redirect_to_home)
        print(rdio.token[0])
        response.set_cookie('at', rdio.token[0], expires=60*60*24*14)   # expires in two weeks
        response.set_cookie('ats', rdio.token[1], expires=60*60*24*14)  # expires in two weeks
        response.set_cookie('rt', '', expires=-1)
        response.set_cookie('rts', '', expires=-1)
        return response
    else:
        response_to_home = make_response(redirect('/'))
        return response_to_home
开发者ID:mrkaiser,项目名称:pardio,代码行数:25,代码来源:services.py

示例9: run

# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import complete_authentication [as 别名]
def run(options):
    store = load_store()
    token = None
    if "token" in store:
        token = (store.get("token"), store.get("token_secret"))
    rdio = Rdio((options.key, options.secret), token)

    if rdio.token == None:
        # No token, log in
        url = rdio.begin_authentication("oob")
        print "Go to: " + url
        verifier = raw_input("Then enter the code: ").strip()
        rdio.complete_authentication(verifier)
        # TODO: Why aren't saved tokens working?
        # token, token_secret = rdio.token
        # store['token'] = token
        # store['token_secret'] = token_secret
        # write_store(store)

    year = options.year
    if year == None:
        year = get_current_year()
    year_key = str(year)

    last_run = None
    if year_key in store:
        last_run = store.get(year_key)

    print "Loading albums"
    albums, last_run = get_albums(rdio, year, last_run)
    print "Loaded %s new albums to add" % len(albums)

    if len(albums) > 0:
        add_to_playlist(rdio, year, albums)

    store[year_key] = last_run
    write_store(store)
开发者ID:monsur,项目名称:another-year,代码行数:39,代码来源:another-year.py

示例10: main

# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import complete_authentication [as 别名]
def main():
	CONSUMER_KEY, CONSUMER_SECRET = get_consumer_credentials()
	rdio = Rdio((CONSUMER_KEY, CONSUMER_SECRET))
	auth_url = rdio.begin_authentication('oob')

	# redirect user to rdio, will give pin back

	verifier = get_pin(auth_url)
	saved_token = rdio.token # a two element tuple
	rdio.complete_authentication(verifier)

	print "fetching last fm artists..."
	lastfm = LastfmQuery.LastfmQuery()
	lastfm_list_of_artists = lastfm.getAlbums("jaisrael")
	
	print "adding artists to collection..." 
	for artist in lastfm_list_of_artists:
		try:
			response = rdio.call('search', {'query':artist, 'types':'Artist'})		
		except UnicodeEncodeError:
			print "unicode issue. skipping this artist"
			continue
	
		artist_key = response['result']['results'][0]['key']
		if artist_key is not None:
			track_objs = rdio.call('getTracksForArtist', {'artist':artist_key})['result']
			track_keys_unicode_list = [ track['key'] for track in track_objs ]
			if track_keys_unicode_list is not None:
				# convert track keys to unicode
				track_keys_ascii_list = [ unicodedata.normalize('NFKD', u).encode('ascii','ignore') for u in track_keys_unicode_list ]
				track_keys_str = ""
				for u in track_keys_ascii_list:
					track_keys_str += u + ","
				if track_keys_str.endswith(','):
					track_keys_str = track_keys_str[:-1]
				atc = rdio.call('addToCollection', {'keys':track_keys_str})
开发者ID:lopatin,项目名称:rdio-sourcing,代码行数:38,代码来源:main.py

示例11: Rdio

# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import complete_authentication [as 别名]
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# include the parent directory in the Python path
import sys,os.path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from rdio import Rdio
from rdio_consumer_credentials import *
from urllib2 import HTTPError

# create an instance of the Rdio object with our consumer credentials
rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET))

try:
  # authenticate against the Rdio service
  url = rdio.begin_authentication('oob')
  print 'Go to: ' + url
  verifier = raw_input('Then enter the code: ').strip()
  rdio.complete_authentication(verifier)

  # find out what playlists you created
  myPlaylists = rdio.call('getPlaylists')['result']['owned']

  # list them
  for playlist in myPlaylists:
    print '%(shortUrl)s\t%(name)s' % playlist
except HTTPError, e:
  # if we have a protocol error, print it
  print e.read()
开发者ID:ColdSauce,项目名称:rdio-simple,代码行数:32,代码来源:command-line.py


注:本文中的rdio.Rdio.complete_authentication方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。