对于Twitter:如何获得用户的oauth_access_token客户端,如facebook,用于服务器端集成

时间:2013-01-25 19:37:15

标签: javascript facebook twitter oauth twitter-anywhere

我正在尝试在服务器端发布facebook和twitter帖子。所以,你点击一个按钮:如果你没有连接,它允许你连接并打开一个对话框覆盖,让你发布一个Facebook / Twitter帖子;如果您已连接,则只需打开叠加层即可。 Facebook的工作原理是因为我可以轻松地在客户端获取所有oAuth密钥,然后将它们传递给服务器。我如何在Twitter上做到这一点? (PS:这是一个完全的AJAX网站,所以我不能指望页面刷新)

在facebook中我这样做:

        if (FB) {
            FB.getLoginStatus(function(response) {
                if (response.status === 'connected') {
                    $.getJSON(window.page.services + "StoreAuthToken", { type: "facebook", socialId: response.authResponse.userID, authId: response.authResponse.accessToken, expiresInSeconds: response.authResponse.expiresIn }, null);
                    window.dialogs.loadFacebookOverlay({ href: href, image: image, description: description, socialId: response.authResponse.userID });
                } else {
                    FB.login(function(response) {
                        if (response.status === 'connected') {
                            $.getJSON(window.page.services + "StoreAuthToken", { type: "facebook", socialId: response.authResponse.userID, authId: response.authResponse.accessToken, expiresInSeconds: response.authResponse.expiresIn }, null);
                            window.dialogs.loadFacebookOverlay({ href: href, image: image, description: description, socialId: response.authResponse.userID });
                        } else { /* user cancled */ }
                    }, { scope: 'share_item' });
                }
            });

如何获取身份验证令牌,可能使用twitter @anywhere代码?

        if (twttr) {
            twttr.anywhere(function(T) {
                if (T.isConnected()) {
                    /* how do I get the auth token here? */
                    window.dialogs.loadTwitter({ href: href, image: image, description: description });
                } else {
                    /* a pop-up is blocked - any way to allow it? */
                    T.signIn();
                }
            });
        }

感谢您的帮助!

0 个答案:

没有答案