1

我正在尝试在服务器端发布 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();
                }
            });
        }

谢谢您的帮助!

4

0 回答 0