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


Python FlickrAPI.auth_getToken方法代码示例

本文整理汇总了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'))
开发者ID:wiredfool,项目名称:fmod,代码行数:59,代码来源:flickr.py


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