本文整理匯總了Python中flickrapi.FlickrAPI.auth_getToken方法的典型用法代碼示例。如果您正苦於以下問題:Python FlickrAPI.auth_getToken方法的具體用法?Python FlickrAPI.auth_getToken怎麽用?Python FlickrAPI.auth_getToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flickrapi.FlickrAPI
的用法示例。
在下文中一共展示了FlickrAPI.auth_getToken方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: cb
# 需要導入模塊: from flickrapi import FlickrAPI [as 別名]
# 或者: from flickrapi.FlickrAPI import auth_getToken [as 別名]
def cb(self):
# this is the callback point for the flickr auth.
# we'll get a parameter of ?frob=123412341234
# we call flickr.auth.getToken with the frob, and get
# xml with the username, the token, and permissions.
fapi = FlickrAPI(config['api_key'], config['api_secret'])
frob = request.params.get('frob')
if not frob:
return "Invalid Response"
rsp = fapi.auth_getToken(frob=frob)
auth = rsp.find('auth')
if not auth:
return "invalid response from get token"
username = auth.find('user').get('username').encode('ascii','ignore')
token = auth.find('token').text
nsid = auth.find('user').get('nsid')
if not (username and token):
return "Invalid Response from getToken"
user = model.User.get_byNsid(nsid)
if not user:
user = model.User.get_byName(username)
if not user:
user = model.User()
user.username = username
user.nsid = auth.find('user').get('nsid')
user.make_secret()
user.save()
user.nsid = nsid
user.commit()
else:
# people can change usernames, nsids are static.
if user.username != username:
user.username=username
user.commit()
session['user'] = username
session['nsid'] = nsid
session['mod'] = user.check_mod(token)
if session['mod']:
session['token'] = token
session.save()
# Send user back to the page he originally wanted to get to
if session.get('path_before_login'):
path = session['path_before_login']
del(session['path_before_login'])
redirect(url(path))
else:
if session.get('mod'):
redirect(url('/ping/index'))
redirect(url('/profile/bookmarklet'))