1

I'm trying to do server-side posting of facebook and twitter posts. So, you click a button: if you're not connected it allows you to connect and opens a dialog overlay to allow you to post a facebook/twitter post; if you are connected it just opens the overlay. Facebook works because I can get all the oAuth keys easily client-side and then pass them to the server. How do I do this in Twitter?
(PS: this is a fully AJAX site so I can't count on page refreshes)

In facebook I do this:

        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' });
                }
            });

How do I get the auth token, maybe using twitter @anywhere code?

        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();
                }
            });
        }

Thank you for your help!

  • Also asked here: dev.twitter.com/discussions/14405 – aproximation Jan 25 '13 at 19:39
  • I've made some progress. Now all I need is the auth token so I can do my server-side stuff. I call the anywhere function like this $(window).bind("load", function(e) { if (twttr) { twttr.anywhere(function(T) { window.twitter = T; }); } }); Then I can call the signIn() without the pop-up being blocked. The problem is that the when I call window.twitter.bind("authComplete", function(e, user) { /* user data doesn't have the auth token */ }); Now, how can I get the auth token now that I'm connected? – aproximation Jan 25 '13 at 22:41

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.