Hi again !
I'm trying to develop a desktop-application javascript based.
I'm actually trying to get the request_token from twitter.
I'm using OAuth js library, and after testing their examples, i'm
trying to do the same thing as
http://oauth.googlecode.com/svn/code/javascript/example/requestToken.html
do, because it seems to work and twitter respond with a valuable
request_token and secret.
To complete the exactly same request, i've been wiresharking my http
request and form the same strings with XMLHttpRequest in my code.
The only response i get is "401 - failed to validate oauth signature
or token", so i assume i make a mistake in basestring generation or
basstring signature.
my code :
function signForm() {
accessor = { consumerSecret: consumer_secret
, tokenSecret : oauth_token_secret};
message = { action: "/request_token"
, method: "POST"
, parameters: []};
message.parameters.push(["oauth_consumer_key", consumer_key]);
message.parameters.push(["oauth_signature_method",
signature_method]);
OAuth.setTimestampAndNonce(message);
OAuth.SignatureMethod.sign(message, accessor);
return true;
}
function getSignature() {
signForm();
console.log(OAuth.getParameter(message.parameters,
"oauth_signature"));
OAuth.completeRequest(message, accessor);
request_maker = new XMLHttpRequest();
request_maker.open("POST", "http://api.twitter.com/oauth/
request_token");
request_maker.setRequestHeader("Host", "api.twitter.com");
request_maker.setRequestHeader("Content-type", "application/x-www-
form-urlencoded");
request_maker.onreadystatechange = oth_func;
request_maker.send("oauth_consumer_key="+consumer_key
+"&oauth_signature_method="+signature_method
+"&oauth_timestamp="+OAuth.getParameter(message.parameters,
"oauth_timestamp")
+"&oauth_nonce="+OAuth.getParameter(message.parameters, "oauth_nonce")
+"&oauth_signature="+encodeURI(OAuth.getParameter(message.parameters,
"oauth_signature")));
}
I've seen some "base64" encoding in some twitter client sources, but
since it's not mentioned in twitter api doc, i don't use base64.
If you have any clue to help me go through this issue, i'd be
gratefull !
--
Twitter developer documentation and resources: http://dev.twitter.com/doc
API updates via Twitter: http://twitter.com/twitterapi
Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list
Change your membership to this group:
http://groups.google.com/group/twitter-development-talk