如何在回调网址中调用javascript函数(jsOAuth + twitter + non-PIN OAuth)

时间:2012-01-03 13:50:27

标签: javascript javascript-events oauth twitter-oauth

了解OAuth,我遇到了一个大问题。 如何使用jsOAuth调用回调网址中的javascript函数?

当您单击连接到Twitter时,将打开登录屏幕,然后Twitter授权APP,并在他简单地调用回调URL之后。 我想关闭此窗口并在发起的页面上调用javascript函数。

See my tests

代码

oauth = OAuth({
            consumerKey: srv.key,
            consumerSecret: srv.secret,
            requestTokenUrl: srv.request_token,
            authorizationUrl: srv.authorize,
            accessTokenUrl: srv.access_token,
            callbackUrl: "http://ridermansb.kodingen.com/twitter.html"
        });

截图

我拿了一些截图会更好地解释:

Authorize

Callback

我问过same question on GitHub;

1 个答案:

答案 0 :(得分:0)

怎么样:

oauth = OAuth({
        consumerKey: srv.key,
        consumerSecret: srv.secret,
        requestTokenUrl: srv.request_token,
        authorizationUrl: srv.authorize,
        accessTokenUrl: srv.access_token,
        callbackUrl: "http://ridermansb.kodingen.com/callback.html"
    });

和callback.html

<html>
<head>
<script type="text/javascript">
/**
 * call parent window function and close
 */
function callback() {
    window.opener.functionName(querystring('token'));
    window.close();
}
</script>
</head>
<body onload="callback()">
</body>
</html>

待测试。