Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 66fb56d

Browse files
committed
More changes to django/twitter oauth documentation in readme
1 parent e68c23c commit 66fb56d

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ can be easily translated to a web application.
8888
# having the user authorize an access token and to sign the request to obtain
8989
# said access token.
9090

91-
resp, content = client.request(request_token_url, "GET")
91+
resp, content = client.request(request_token_url, "POST", body="oauth_callback=oob")
9292
if resp['status'] != '200':
9393
raise Exception("Invalid response %s." % resp['status'])
9494

@@ -218,7 +218,7 @@ and code here might need to be updated if you are using Python 2.6+.
218218

219219
def twitter_login(request):
220220
# Step 1. Get a request token from Twitter.
221-
resp, content = client.request(request_token_url, "POST", body=urlencode({'oauth_callback':"/"})
221+
resp, content = client.request(request_token_url, "POST", body="oauth_callback=http://<base-URL>login/authenticated/")
222222
if resp['status'] != '200':
223223
raise Exception("Invalid response from Twitter.")
224224

@@ -243,10 +243,14 @@ and code here might need to be updated if you are using Python 2.6+.
243243
# Step 1. Use the request token in the session to build a new client.
244244
token = oauth.Token(request.session['request_token']['oauth_token'],
245245
request.session['request_token']['oauth_token_secret'])
246+
247+
if 'oauth_verifier' in request.GET:
248+
token.set_verifier(request.GET['oauth_verifier'])
249+
246250
client = oauth.Client(consumer, token)
247251

248252
# Step 2. Request the authorized access token from Twitter.
249-
resp, content = client.request(access_token_url, "GET")
253+
resp, content = client.request(access_token_url, "POST")
250254
if resp['status'] != '200':
251255
print content
252256
raise Exception("Invalid response from Twitter.")
@@ -272,10 +276,16 @@ and code here might need to be updated if you are using Python 2.6+.
272276
# These two things will likely never be used. Alternatively, you
273277
# can prompt them for their email here. Either way, the password
274278
# should never be used.
275-
user = User.objects.create_user(access_token['screen_name'],
276-
'%[email protected]' % access_token['screen_name'],
277-
access_token['oauth_token_secret'])
278-
279+
280+
281+
user = User.objects.create_user(username=access_token['screen_name'],
282+
email='%[email protected]' % access_token['screen_name'],
283+
password=access_token['oauth_token_secret'])
284+
# Need to reset password because set_password saves the password as a hash
285+
# whereas the constructor above saves plaintext
286+
user.set_password(access_token['oauth_token_secret'])
287+
user.save()
288+
279289
# Save our permanent token and secret for later.
280290
profile = Profile()
281291
profile.user = user

0 commit comments

Comments
 (0)