Hi, I'm using jQuery's AJAX to interact with Twitter.
I'm trying to implement, at first, the authentication through oauth.
So, I'm using Oauth JavaScript library to build data to be sent, and
then using jQuery's AJAX to send it.

Code:
var Oauth_request = { action: "https://api.twitter.com/oauth/
request_token",
                                          method: "POST",
                                          parameters: 
[["oauth_consumer_key","my_oauth_consumer_key"],
                                                                   
["oauth_signature_method","HMAC-SHA1"],
                                                                   
["oauth_signature",""],
                                                                   
["oauth_timestamp",""],
                                                                   
["oauth_nonce",""]
                                                                  ]
                                        };

var Oauth_accessor = { consumerSecret: "MyconsumerSecret"
                                    , tokenSecret   : ""};


OAuth.setTimestampAndNonce(Oauth_request);

OAuth.SignatureMethod.sign(Oauth_request, Oauth_accessor);

var parameterMap = OAuth.getParameterMap(Oauth_request.parameters);

OAuth.completeRequest(Oauth_request, Oauth_accessor);

var requestBody = OAuth.formEncode(Oauth_request.parameters);

var authorizationHeader = OAuth.getAuthorizationHeader("",
Oauth_request.parameters);

//jQuery Start
$(function(){

        $.ajax({
                type : Oauth_request.method,
                url  : Oauth_request.action,
        beforeSend: function(xhrObj){
            xhrObj.setRequestHeader("Content-Type","application/x-www-
form-urlencoded");
                        
xhrObj.setRequestHeader("Authorization",authorizationHeader);
        },
                //contentType : "application/x-www-form-urlencoded",
                data : requestBody ,
                dataType: "json",

                processData: false,

               complete: function(xhrObj, textStatus){
                        if(xhrObj.readyState == 4){
                                var dump = xhrObj.status+" "+xhrObj.statusText
                  +"\n"+xhrObj.getAllResponseHeaders()
                  +"\n"+xhrObj.responseText;
                                var results = 
OAuth.decodeForm(xhrObj.responseText);
                                alert(textStatus);
                        }
                },
                success: function(data, textStatus, XMLHttpRequest){

                        var results = 
OAuth.decodeForm(XMLHttpRequest.responseText);
                        $("#Response").html(XMLHttpRequest.readyState);
                        //$("#Response").html(data);
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                        //alert(XMLHttpRequest);
                        //$("div").html(textStatus);
                        $("#Response").html(XMLHttpRequest.status);
                        //alert(errorThrown);
                }



        })

  });

});

</script>

-- 
You received this message because you are subscribed to the Google Groups 
"OAuth" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/oauth?hl=en.

Reply via email to