xAuth for getting access token


Hello All,

I have created simple python program from which i can login to twitter by using specific user_name and password but,
i can not authorized particular user with their right user_name and password

i had done all the procedure perfectly than also i am getting status :401

here is my code :

import oauth2 as oauth
import urllib

access_token_url = ‘https://api.twitter.com/oauth/access_token

consumer = oauth.Consumer(consumer_key, consumer_secret)
client = oauth.Client(consumer)

params = {}
params[“x_auth_username”] = "user_name"
params[“x_auth_password”] = "password"
params[“x_auth_mode”] = ‘client_auth’

client.set_signature_method = oauth.SignatureMethod_HMAC_SHA1()
resp, token = client.request(access_token_url, method=“POST”,body=urllib.urlencode(params))

print “resp:::”,resp
print “token::”,token

output :

resp::: {‘status’: ‘401’, ‘content-length’: ‘459’, ‘x-transaction’: ‘f52ee037325deb1c’, ‘set-cookie’: ‘k=; path=/; expires=Tue, 16-Oct-12 14:30:47 GMT; domain=.twitter.com, guest_id=v1%3A134979304710782631; domain=.twitter.com; path=/; expires=Fri, 10-Oct-2014 02:30:47 GMT, _twitter_sess=BAh7CCIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCERi70U6AToHaWQiJTE4%250AM2RlZmQ0M2FlNmQyOWYxN2RkMmQ2NDM5NWU3ZjNh–488c43807ea0f3f779a80313438bfebb7ec9b3c5; domain=.twitter.com; path=/; HttpOnly’, ‘expires’: ‘Tue, 31 Mar 1981 05:00:00 GMT’, ‘x-mid’: ‘1470dfa874f5e2fd4fb393f8cec5fe9c26d3a706’, ‘server’: ‘tfe’, ‘last-modified’: ‘Tue, 09 Oct 2012 14:30:47 GMT’, ‘x-runtime’: ‘0.02498’, ‘-content-encoding’: ‘gzip’, ‘pragma’: ‘no-cache’, ‘cache-control’: ‘no-cache, no-store, must-revalidate, pre-check=0, post-check=0’, ‘date’: ‘Tue, 09 Oct 2012 14:30:47 GMT’, ‘x-frame-options’: ‘SAMEORIGIN’, ‘content-type’: ‘application/xml; charset=utf-8’, ‘www-authenticate’: ‘OAuth realm=“https://api.twitter.com”’, ‘vary’: ‘Accept-Encoding’}

token:: <?xml version="1.0" encoding="UTF-8"?>

xAuth का प्रयोग करने के लिए क्लाएंट अनुप्रयोग को अनुमति नहीं है.

i am getting response perfectly but i can’t get the access token for specific user so is there any another way to get the user specific access token to access twitter account data or if i missed something in my code that please let me know .

Thanks & Regards

Anil Kesariya


First, I recommend not posting your consumer key and secret to a public forum.

The error message you’re getting indicates you don’t have permission to use xAuth – xAuth requires a vetting process by our API policy team and must only be used when there are no reasonable alternatives.

You likely can perform web-based or PIN-code based OAuth without issue in your environment. Have you read through the OAuth documentation yet?