没有密码的Twitter codebird.js授权

时间:2014-09-04 15:58:20

标签: javascript twitter

我想问一下是否可以通过绕过pincode条目使用codebird.js在Twitter上授权app。这是我的代码(使用密码):

$(document).ready(function () {
$("#twitterLogin").on("click", function() {
    // handle button click here
    cb.__call(
        "oauth_requestToken",
        {oauth_callback: "oob"},
        function (reply) {
            // stores it
            cb.setToken(reply.oauth_token, reply.oauth_token_secret);

            // gets the authorize screen URL
            cb.__call(
                "oauth_authorize",
                {},
                function (auth_url) {
                    //window.open(auth_url);
                    window.open(auth_url,"MsgWindow",'height=202,width=800');
                }
            );
        }
    );

});

$("#tweet").on("click", function() {
    cb.__call(
        "oauth_accessToken",
        {oauth_verifier: document.getElementById("rhymeText").value},
        function (reply) {
            // store the authenticated token, which may be different from the request
token (!)
            cb.setToken(access_token_key, access_token_secret);
            alert('Auth completed!');
            // if you need to persist the login after page reload,
            // consider storing the token in a cookie or HTML5 local storage
        }
    );
});

$("#auth").on("click", function() {
    cb.__call(
        "statuses_updateWithMedia",
        {
            "status": "The bird is on fire!. @gaspersopi",
            "media[]": "iVB..SuQmCC"
        },
        function (reply) {
            console.log(reply);
            alert('Image posted!');
        }
    );

});

var consumer_key = "ao856hSerLRDH1xXyfSXvvYRs";
var consumer_secret = "9jMK2f74QyCeAlpikmn4VIfjZkvnOxQ3pmYEviez86yaS9PRoH";

var access_token_key = "955855880-ko408mWNBWbWLbDqe2MjF3cpXvmPKzVQzFZW5YOj";
var access_token_secret = "J6Yh0ZvAoWaeve7CMCQ9RbRLcj8ISbNTZ4qVKCBp95N1U";

var cb = new Codebird;
var current_url = location.toString();

cb.setConsumerKey(consumer_key, consumer_secret);

});

这也是我所说的但它没有用,因为匹配方法总是返回null。

var cb          = new Codebird;
var current_url = location.toString();
var query       = current_url.match(/\?(.+)$/).split("&");
var parameters  = {};
var parameter;

cb.setConsumerKey("STUFF", "HERE");

for (var i = 0; i < query.length; i++) {
parameter = query[i].split("=");
if (parameter.length === 1) {
    parameter[1] = "";
}
parameters[decodeURIComponent(parameter[0])] = decodeURIComponent(parameter[1]);
}

// check if oauth_verifier is set
if (typeof parameters.oauth_verifier !== "undefined") {
// assign stored request token parameters to codebird here
// ...
cb.setToken(stored_somewhere.oauth_token, stored_somewhere.oauth_token_secret);

cb.__call(
    "oauth_accessToken",
    {
        oauth_verifier: parameters.oauth_verifier
    },
    function (reply) {
        cb.setToken(reply.oauth_token, reply.oauth_token_secret);

        // if you need to persist the login after page reload,
        // consider storing the token in a cookie or HTML5 local storage
    }
);
}

提前致谢..

1 个答案:

答案 0 :(得分:0)

cb.__call(
     "oauth_authorize",
     **{oauth_callback: "yourdomain/callback.html"}**,
     function (auth_url) {
          //window.open(auth_url);
           window.open(auth_url,"MsgWindow",'height=202,width=800');
      }
);

你应该把oauth_callback参数,它注册到你的应用程序 和回调网页使编码获得回复。