本文整理汇总了Python中models.Player.twitter_oauth_token方法的典型用法代码示例。如果您正苦于以下问题:Python Player.twitter_oauth_token方法的具体用法?Python Player.twitter_oauth_token怎么用?Python Player.twitter_oauth_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Player
的用法示例。
在下文中一共展示了Player.twitter_oauth_token方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: twitter_callback
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import twitter_oauth_token [as 别名]
def twitter_callback(request):
""" This method deals with the callback needed by twitter, and creating the their user.
"""
if 'denied' in request.GET:
return HttpResponseRedirect('/')
twitter_conn = twitter(
twitter_token = keys.CONSUMER_KEY,
twitter_secret = keys.CONSUMER_SECRET,
oauth_token = request.session['request_token']['oauth_token'],
oauth_token_secret = request.session['request_token']['oauth_token_secret']
)
auth_tokens = twitter_conn.get_authorized_tokens()
try:
user = User.objects.get(username = auth_tokens['screen_name'])
except User.DoesNotExist:
user = create_django_user(auth_tokens['screen_name'], auth_tokens['oauth_token_secret'])
player = Player()
player.user = user
player.twitter_oauth_token = auth_tokens['oauth_token']
player.twitter_oauth_secret = auth_tokens['oauth_token_secret']
request.session['twitter'] = player
form = PlayerForm(initial={'username': player.user.username})
return render(request, 'register.html', {'form': form})
player = Player.objects.get(user=user)
user = authenticate(username=player.user.username, password=player.twitter_oauth_secret)
login(request, user)
return HttpResponseRedirect('/')