本文整理汇总了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'))