当twitter用户登录我的网站时,'function'对象没有属性'key',(我的网站使用django)

时间:2011-01-01 03:00:07

标签: python django twitter

我按照这篇文章:http://hameedullah.com/step-by-step-guide-to-use-sign-in-with-twitter-with-django.html使用twitter登录。

这是我的django twitter登录的回调方法:

def callback(req):
    token = req.session.get('token', None)
    if not token:
        return render_to_response('twitter/callback.html', {
            'token': True
        })
    token = oauth.OAuthToken.from_string(token)
    if token.key != req.GET.get('oauth_token', 'no-token'):
        return render_to_response('twitter/callback.html', {
            'mismatch': True
        })
    #token = get_authorized_token(token)
    access_token = exchange_request_token_for_access_token(token)
    o=access_token
    s = ''.join('%s: %s </br>' % (a, getattr(o, a)) for a in dir(o))
    return  HttpResponse(s)
    # Actually login
    obj = is_authorized(token)
    if obj is None:
        return render_to_response('twitter/callback.html', {
            'username': True
        })


    try: user = User.objects.get(username=obj['screen_name'])
    except: user = User(username=obj['screen_name'])
    twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, token)

    try:
        UserTwitter.objects.get(facebook_id=request.facebook.uid)
        # already setup, move along please
        return HttpResponseRedirect(redirect_url)
    except FacebookProfile.DoesNotExist, e:
        # not in the db, ok to continue
        pass
    user.oauth_token = token.key
    user.oauth_token_secret = token.secret
    user.save()
    req.session['user_id'] = user.id


    req.session['twitter_user'] = user.username
    req.session['twitter_email'] = user.email
    #s = ''.join('%s: %s </br>' % (a, getattr(user, a)) for a in dir(user))
    #s = ''.join('%s: %s </br>' % (a,getattr(user, a)) for a in dir(user) if '__' not in a )

    #return HttpResponse(user.username+' </br>'+user.email)
    #return HttpResponseRedirect(reverse('user_register',kwargs={'username':username,'email':email}))
    return HttpResponseRedirect(reverse('user_register'))

并显示错误:

'function' object has no attribute 'key'

我能做什么。

感谢

0 个答案:

没有答案