OAuth请求令牌错误:flickr中的401

时间:2014-01-08 09:48:08

标签: javascript angularjs oauth flickr

我正在开发一个用于将图片上传到flickr的移动应用程序。但我甚至不能做第一步,即成功请求令牌。我签署了基本URL并将签名参数添加到代码中。我在AngularJS之外使用了http://oauth.googlecode.com/svn/code/javascript/oauth.jshttp://oauth.googlecode.com/svn/code/javascript/sha1.js库。 发送GET请求如下。

$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");
            });
    }

以下网络状态出现错误:

    GET http://www.flickr.com/services/oauth/request_tok...1&oauth_signature=h0pdL6ZzYqGnGsrHbqjwFCIGg2Y%3D 
401 Unauthorized

我在控制台中记录了以下参数。

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

特征

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

我在浏览器中输入了RequestTokenURL并得到了这个结果:

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

1 个答案:

答案 0 :(得分:1)

这个javascript库可能会帮助您处理OAuth的内容:oauth-1.0a

它支持客户端和node.js

干杯