2011-01-17 13 views
1

私は私のDjangoアプリケーションでのOAuth経由でTwitterの認証を実装しようとしているが、私はTwitterのコールバックを受け取った後に、このエラーにこだわっている:ジャンゴTwitterのOAuth認証

Traceback: 

File "/Library/Python/2.6/site-packages/django/core/handlers/base.py" in get_response 
    100.      response = callback(request, *callback_args, **callback_kwargs) 
File "/Users/flavioramos/projects/sobo/sobo/../sobo/views.py" in twitter_authenticated 
    105.  auth_login(request, user) 
File "/Library/Python/2.6/site-packages/django/contrib/auth/__init__.py" in login 
    71.  user.save() 
File "/Library/Python/2.6/site-packages/django/contrib/auth/models.py" in save 
    430.   raise NotImplementedError 

Exception Type: NotImplementedError at /login/authenticated 
Exception Value: 

私のログイン/認証されたビューがあります次のようになります。

def twitter_authenticated(request): 
    token = oauth.Token(request.session['request_token']['oauth_token'], 
     request.session['request_token']['oauth_token_secret']) 
    client = oauth.Client(consumer, token) 

    resp, content = client.request(access_token_url, "GET") 
    if resp['status'] != '200': 
     print content 
     raise Exception("Invalid response from Twitter.") 

    access_token = dict(cgi.parse_qsl(content)) 

    try: 
     user = User.objects.get(username=access_token['screen_name']) 
    except User.DoesNotExist: 
     user = User.objects.create_user(access_token['screen_name'], 
      '%[email protected]' % access_token['screen_name'], 
      access_token['oauth_token_secret']) 

     profile = Profile() 
     profile.user = user 
     profile.oauth_token = access_token['oauth_token'] 
     profile.oauth_secret = access_token['oauth_token_secret'] 
     profile.save() 


    user = authenticate(username=access_token['screen_name'],password=access_token['oauth_token_secret']) 

    auth_login(request, user) 

    return HttpResponseRedirect('/') 

このコードはpython-oauth2サンプルアプリケーションからのものです。

このために独自の認証バックエンドを作成する必要がありますか?

私はDjangoで新しいですし、どんな助けもありがとうございます。

おかげで、

答えて

1

私も同じ問題がありました。 oauthtwitterによって使用されるlibsが変更されたようです。あなたのローカルバージョンにパッチを適用するには、次の操作を行います。

に:

/usr/local/lib/python2.6/dist-packages/oauth_python_twitter-1.0-py2.6.egg/oauthtwitter.py 

検索線37とからそれを変更します。

Api.__init__(self, access_token.key, access_token.secret) 

へ:今、必要なすべての

Api.__init__(self, consumer_key, consumer_secret, access_token.key, access_token.secret) 

変数は正しく渡されます。

0

かなりわからないが、私は

* auth_login(リクエスト、利用者)*

がされるべきだと思う:ログイン(リクエスト、ユーザー)

(とofcourse ログインは、ログイン/認証ビューの上にdjango.contib.authからインポートする必要があります