Reputation: 7468
I'm developing a mobile application for uploading pictures to flickr. But I can't even do the first step ie.,request token successfully. I signed the the base url and added the signature parameter to the code. I used the http://oauth.googlecode.com/svn/code/javascript/oauth.js
and http://oauth.googlecode.com/svn/code/javascript/sha1.js
libraries in this other than AngularJS.
Sent the GET request as follows.
$scope.test=function(){
var preURL="http://www.flickr.com/services/oauth/request_token";
var accessor = {
consumerSecret: "a3439ab5915a03e4c",
tokenSecret : ""
};
var message = {
method: "GET",
action: preURL,
parameters: OAuth.decodeForm("oauth_callback=http%3A%2F%2Fwww.flickr.com")
};
message.parameters.push(["oauth_version", "1.0"]);
message.parameters.push(["oauth_consumer_key", "1cfb4bb9b0e0bec71554e66da9da4582"]);
message.parameters.push(["oauth_timestamp", OAuth.timestamp()]);
message.parameters.push(["oauth_nonce", OAuth.nonce(11)]);
message.parameters.push(["oauth_signature_method", "HMAC-SHA1"]);
OAuth.SignatureMethod.sign(message, accessor);
console.log("signatureBaseString" + OAuth.SignatureMethod.getBaseString(message));
console.log("signature" + OAuth.getParameter(message.parameters, "oauth_signature"));
var requestTokenURL=OAuth.addToURL(preURL,message.parameters);
console.log(requestTokenURL);
$http({
method: message.method,
url: requestTokenURL
}).
success(function(data, status, headers, config) {
console.log("success");
}).
error(function(data, status, headers, config) {
console.log("error");
});
}
An error is occuring with the following Network status:
GET http://www.flickr.com/services/oauth/request_tok...1&oauth_signature=h0pdL6ZzYqGnGsrHbqjwFCIGg2Y%3D
401 Unauthorized
I logged the following parameters in console.
signatureBaseString:
GET&http%3A%2F%2Fwww.flickr.com%2Fservices%2Foauth%2Frequest_token&oauth_callback%3Dhttp%253A%252F%252Fwww.google.com%26oauth_consumer_key%3D1cfb4bb9b0e0bec71554e66da9da4582%26oauth_nonce%3DzKxKd3VJxEB%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1389180736%26oauth_version%3D1.0
Signature
h0pdL6ZzYqGnGsrHbqjwFCIGg2Y=
RequestTokenURL
http://www.flickr.com/services/oauth/request_token?oauth_callback=http%3A%2F%2Fwww.google.com&oauth_version=1.0&oauth_consumer_key=1cfb4bb9b0e0bec71554e66da9da4582&oauth_timestamp=1389180736&oauth_nonce=zKxKd3VJxEB&oauth_signature_method=HMAC-SHA1&oauth_signature=h0pdL6ZzYqGnGsrHbqjwFCIGg2Y%3D
I entered the RequestTokenURL in browser and got this result:
oauth_problem=signature_invalid&debug_sbs=GET&http%3A%2F%2Fwww.flickr.com%2Fservices%2Foauth%2Frequest_token&oauth_callback%3Dhttp%253A%252F%252Fwww.google.com%26oauth_consumer_key%3D1cfb4bb9b0e0bec71554e66da9da4582%26oauth_nonce%3D6XctoZTWmaH%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1389181211%26oauth_version%3D1.0
Upvotes: 2
Views: 825
Reputation: 395
This javascript library might help you on OAuth's stuff: oauth-1.0a
It support both client side and node.js
Cheers
Upvotes: 1