Issues with "Request Token"


#1

I’m currently working on implementing an authorization feature into my app using the “three-legged” approach. In order to obtain the request token (using a POST call) I use Ajax to ask for the request token. My application is reporting ‘success’ after the call, as the server is returning an object; however, this object is strangely an HTML file- to be more specific, the HTML file of my program- instead of the string token to be exchanged for the access token. Has anyone experienced a problem of this sort?

function getTweets() {
  var currentTime = new Date();
  var time = currentTime.getTime();
  var code = getNonce();
	$.ajax({
	  type: "POST",
	  data: {
	    _url: "https://api.twitter.com/oauth/request_token"
	  },
	  dataType: "text",
	  headers: {  
	    "oauth_nonce": code,
	    "oauth_callback": "http%3A%2F%2Fgoogle.com%2F",
      "oauth_signature_method": "HMAC-SHA1",
      "oauth_timestamp": time,
      "oauth_consumer_key": "xxx",       
      "oauth_signature": "xxx",
      "oauth_version": "1.0"
    },
	  success: function(data) {
	    alert("Success!");
	    console.log(data);
	  },
	  error: function(data) {
	    alert("Something went wrong...");
	    console.log(data);
	  }
	});
}

function getNonce() {
  var code = "";
  for (var i = 0; i < 20; i++) {
    code += Math.floor(Math.random() * 9).toString();
  }
  return code;
}  


#2

We don’t generally offer support for attempts to use OAuth via Javascript – it’s not recommended by us.