Unable to authenticate from javascript

snehaljpatel
@snehaljpatel Snehal Patel

Hi,
I have tried many times to authenticate using oauth. following is the code from javascript. It will get status 0 in error callback after making ajax call.
Please help me.. it is urgent.

  1. <head>
  2.     <title>:: Twitter Login ::</title>
  3.     <script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
  4.     <script type="text/javascript">
  5.         function GetTwitter() {
  6.             $.ajax({
  7.                 type: "POST",
  8.                 url: "https://api.twitter.com/oauth/request_token",
  9.                 beforeSend: SetHeaders,
  10.                 success: function (msg) {
  11.                     alert(msg);
  12.                 },
  13.                 error: function (xhr) {
  14.                     alert("An error occured : " + xhr.status + " " + xhr.statusText);
  15.                 }
  16.             });
  17.         }
  18.  
  19.         function SetHeaders(xhr) {
  20.             xhr.setRequestHeader("oauth_callback", "http://localhost/wwm/default2.asp");
  21.             xhr.setRequestHeader("oauth_consumer_key", "UYXhGdMgUG4mx9Fq6Ztjw");
  22.             xhr.setRequestHeader("oauth_nonce", "QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk");
  23.             xhr.setRequestHeader("oauth_signature_method", "HMAC-SHA1");
  24.             xhr.setRequestHeader("oauth_signature", encodeURI("gSuISr7V9wFHQTcpidzdzwGwSiFamDCug7nAHs3pMeE"));
  25.             xhr.setRequestHeader("oauth_timestamp", "1272323042");
  26.             xhr.setRequestHeader("oauth_version", "1.0");
  27.         }
  28.     </script>
  29. </head>
  30. <body>
  31.     <input id="Button1" type="button" value="Get Twitter" onclick="GetTwitter();" />
  32. </body>
2 years 23 weeks ago

Replies

episod
@episod Taylor Singletary

OAuth 1.0A is not allowed on Twitter through client-side Javascript. If you want to implement a client-side solution, I recommend using our Web Intents instead. Otherwise, a server-side integration may be a better bet.

2 years 23 weeks ago
564500178
@564500178 失落非主流

Web Intents Supported Parameters text how to with image??

51 weeks 3 days ago
mhang3276
@mhang3276 Michael Hang

Is there any particular reason that Javascript-sent OAuth 1.0A is not allowed on Twitter? I understand that Javascript is not secure in terms of hiding the consumer key/secret, but I'm simply using it to send an HTTP request for authentication. I suppose a more specific question: is client-side Javascript incompatible with the way that Twitter accepts OAuth requests or does Twitter actively block requests made with Javascript?

Thanks.

1 year 42 weeks ago
kbbagal
@kbbagal Kishor Bagal

How to generate oauth_nonce , oauth_signature ?

22 weeks 2 days ago
makamrakesh1
@makamrakesh1 makam rakesh

how to sign up with twitter in JavaScript

17 weeks 6 days ago