I am trying to implement twitter authentication by following this documentation. In the first step it mentions about obtaining a request token by sending post request to https://api.twitter.com/oauth/request_token URL.
I have tried using the folowing jQuery AJAX call:
$.ajax({
url: 'https://api.twitter.com/oauth/request_token',
type: 'POST',
data:
{
oauth_consumer_key: "VshAvsn9hM70llcNkBd0AEtoG",
oauth_token: "348340406-gqIe02ZD5aPSfvauvpgcRlwYfcHVF0OovvbCv2hB"
},
dataType: 'json',
success: function (data) {
alert(data);
}
});
The above call throws 400 Bad Request. How exactly should I do a post request to obtain the request token from twitter oauth api?
Edit:
I have tried in the following way:
$.ajax({
url: 'https://api.twitter.com/oauth/request_token',
type: 'POST',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'OAuth oauth_consumer_key="VshAvsn9hM70llcNkBd0AEtoG", oauth_nonce="babde0df02243087691ff953b5dccfec", oauth_signature="3iPaxYFbhODAdTXEj3dhoJBQCfw%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1433665312", oauth_token="348340406-gqIe02ZD5aPSfvauvpgcRlwYfcHVF0OovvbCv2hB", oauth_version="1.0", oauth_callback="http://www.google.com"');
},
dataType: 'jsonp',
success: function (data) {
alert(data);
}
});
Now its throwing the following error:
{"errors":[{"code":32,"message":"Could not authenticate you."}]}