本文整理汇总了Python中rdio.Rdio.begin_authentication方法的典型用法代码示例。如果您正苦于以下问题:Python Rdio.begin_authentication方法的具体用法?Python Rdio.begin_authentication怎么用?Python Rdio.begin_authentication使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdio.Rdio
的用法示例。
在下文中一共展示了Rdio.begin_authentication方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import begin_authentication [as 别名]
def login():
access_token = session.get('at')
access_token_secret = session.get('ats')
if access_token and access_token_secret:
rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET), (access_token, access_token_secret))
try:
rdio_data = rdio.call('currentUser', params={'extras': 'username,displayName'})['result']
username = rdio_data['username']
user = User.query.filter(User.username == username).first()
session['user_id'] = user.id
print current_user
return redirect(url_for('main'))
except urllib2.HTTPError:
# Something went horribly wrong, like Rdio told us our app sucks.
logout()
return redirect(url_for('main'))
else:
session['at'] = ''
session['ats'] = ''
session['rt'] = ''
session['rts'] = ''
rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET))
login_url = rdio.begin_authentication(callback_url='http://' + request.host + '/auth')
session['rt'] = rdio.token[0]
session['rts'] = rdio.token[1]
return jsonify(login_url=login_url)
示例2: login
# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import begin_authentication [as 别名]
def login():
session['at'] = ''
session['ats'] = ''
session['rt'] = ''
session['rts'] = ''
# begin the authentication process
rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET))
url = rdio.begin_authentication(callback_url = 'http://localhost:5000/callback')
# save our request token in cookies
session['rt'] = rdio.token[0]
session['rts'] = rdio.token[1]
# go to Rdio to authenticate the app
return redirect(url)
示例3: GET
# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import begin_authentication [as 别名]
def GET(self):
# clear all of our auth cookies
web.setcookie('at', '', expires=-1)
web.setcookie('ats', '', expires=-1)
web.setcookie('rt', '', expires=-1)
web.setcookie('rts', '', expires=-1)
# begin the authentication process
rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET))
url = rdio.begin_authentication(callback_url = web.ctx.homedomain+'/callback')
# save our request token in cookies
web.setcookie('rt', rdio.token[0], expires=60*60*24) # expires in one day
web.setcookie('rts', rdio.token[1], expires=60*60*24) # expires in one day
# go to Rdio to authenticate the app
raise web.seeother(url)
示例4: login
# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import begin_authentication [as 别名]
def login():
#clear all of our auth cookies
#begin auth
rdio = Rdio(RDIO_CREDENTIALS)
app.logger.debug(request.host)
url = rdio.begin_authentication(callback_url='http://'+request.host+'/callback')
redirect_to_rdio = redirect(url)
#save our request token in cookies
response = make_response(redirect_to_rdio)
print(rdio.token)
response.set_cookie('rt', rdio.token[0], expires=60*60*24)
response.set_cookie('rts', rdio.token[1], expires=60*60*24)
#go to Rdio to authenticate the app
return response
示例5: login
# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import begin_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)
示例6: tester
# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import begin_authentication [as 别名]
def tester():
rdio = Rdio(("u35btmntr29vd3n9hnuy9m6n", "jb8DTyHpVf"))
url = rdio.begin_authentication('oob')
saved_token = rdio.token
print saved_token
rdio = Rdio(("u35btmntr29vd3n9hnuy9m6n", "jb8DTyHpVf"), saved_token)
#print "Go to website to verify: " + url
#verifier = input("Enter pin: ")
#rdio.complete_authentication(saved_token)
print saved_token
song = rdio.call("search",{"query": "Lose yourself","types":"Track"})
if(song["status"] == "ok"):
track = song["result"]["results"][0]["key"]
rdio.call("addToPlaylist",{"playlist":"p8696966","tracks":str(track)})
else:
print "failed"
return "Song Added"
示例7: run
# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import begin_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)
示例8: main
# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import begin_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})
示例9: Rdio
# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import begin_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()
示例10: index
# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import begin_authentication [as 别名]
def index():
playlist_url = None
artists=[]
if current_user.is_authenticated():
sign_in = False
user = rdio_oauth_tokens.find_one({'user_key': current_user.get_id()})
user_name = user['user_name']
user_key = user['user_key']
token = tuple(user['token'])
rdio = Rdio((CONSUMER_KEY, CONSUMER_SECRET), token)
logger.debug('{} ({}) is authenticated'.format(user_name, user_key))
else:
sign_in = True
user_name = None
if flask.request.method == 'POST':
logger.debug('Method: POST, user: {}'.format(user_name))
if 'signin' in flask.request.form.keys():
logger.debug('Signing in')
rdio = Rdio((CONSUMER_KEY, CONSUMER_SECRET))
auth_url = rdio.begin_authentication(OAUTH_CALLBACK_URL)
session_id = flask.request.cookies['session']
inserted_temp_token = oauth_temp_db.insert({'oauth token': rdio.token[0], 'oauth_dance_token': rdio.token})
logger.debug('inserted token: {}'.format(inserted_temp_token))
logger.debug('Redirecting to Rdio oauth')
return flask.redirect(auth_url)
if 'artistname' in flask.request.form.keys():
search_artist = flask.request.form['artistname']
artists = lib.create_artist_list(search_artist, rdio)
if 'create playlist' in flask.request.form.keys():
token = tuple(rdio_oauth_tokens.find_one(
{'user_key': current_user.get_id()})['token'])
playlist_url = lib.create_rdio_playlist(token, flask.request)
return flask.redirect('http://rdio.com{}'.format(playlist_url))
if 'logout' in flask.request.form.keys():
logout_user()
logger.debug('User logged out.')
return flask.redirect('/')
if flask.request.method == 'GET':
logger.debug('Method: GET')
if 'oauth_token' in flask.request.args.keys():
logger.debug('Oauth callback.')
access_token = lib.rdio_access_token(flask.request, oauth_temp_db)
rdio = Rdio((CONSUMER_KEY, CONSUMER_SECRET), access_token)
user = rdio.call("currentUser")['result']
user_key, user_name = user['key'], user['firstName']
if rdio_oauth_tokens.find_one({'user_key': user_key}) is None:
logger.debug('User not in database, inserting:')
logger.debug(rdio_oauth_tokens.insert({'user_key': user_key,
'token': rdio.token,
'user_name': user_name}))
else:
logger.debug('User found in database.')
pass
session_user = FlaskLoginUser(user_key)
logger.debug('Logging in: {}'.format(session_user))
login_user(session_user)
flask.session['logged_in'] = True
sign_in = False
return flask.redirect('/')
return flask.render_template('index.html', artists=artists, sign_in=sign_in,
user_name=user_name, playlist_url=playlist_url)
示例11: Rdio
# 需要导入模块: from rdio import Rdio [as 别名]
# 或者: from rdio.Rdio import begin_authentication [as 别名]
config['consumer_key'] = options.consumer_key
if options.consumer_secret is not None:
config['consumer_secret'] = options.consumer_secret
if not config.has_key('consumer_key') or not config.has_key('consumer_secret'):
sys.stderr.write('Both the consumer key and consumer secret must be specified')
sys.exit(1)
if options.forget_auth or options.authenticate:
config['auth_state'] = {}
rdio = Rdio(config['consumer_key'], config['consumer_secret'], config['auth_state'])
if options.authenticate:
import webbrowser
webbrowser.open(rdio.begin_authentication('oob'))
verifier = raw_input('Enter the PIN from the Rdio site: ').strip()
rdio.complete_authentication(verifier)
f = file(config_path, 'w')
json.dump(config, f, indent=True)
f.write('\n')
method = args.pop(0)
args = dict([a.split('=',1) for a in args])
response, content = rdio.call_raw(method, **args)
if response['status'] == '200':
print content
else:
if options.verbose:
if response.has_key('www-authenticate'):