Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7530673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:58:30+00:00 2026-05-30T04:58:30+00:00

Please tell me if I’m understanding correctly. (because I might not be.) User posts

  • 0

Please tell me if I’m understanding correctly. (because I might not be.)

  1. User posts something on my site. (He checked “also post to Facebook”.)
  2. Client sends an AJAX POST request to my server, and my server inserts the record in my database.
  3. The server realizes the the facebook user access token is expired, so it sends the response back to the client, while storing the post in a session.
  4. The client does a window.location.replace(facebook_oauth_dialog_url)
  5. Then the user will see a sudden “flash”, going to Facebook, then coming back to the website. My server picks up the new access token.
  6. My server checks the session to see what should be posted to Facebook. And then, it uses the new access token to post that to Facebook.

Is it really this tedious? Why can’t I renew the app server-side without the user going through the dialog?

My entire site is Backbone.js. That means, it’s one big page. I can’t jump the user back and forth between Facebook and my website like this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:58:31+00:00Added an answer on May 30, 2026 at 4:58 am

    The idea is to make use of the Facebook JS-SDK methods:

    1. User check the Post To Facebook option
    2. you check if the current user is connected to your app (using FB.getLoginStatus())
    3. if the user is connected, you have two options:
      • post directly using the FB.api method or
      • Send the access_token to your server to complete the post process there
    4. if the user is not connected (or not logged in to Facebook), use the FB.login() method

    Here’s a quick example (with a Live Demo!) for you to get started:

    <!DOCTYPE html>
    <html xmlns:fb="http://www.facebook.com/2008/fbml">
    <body>
    <div id="fb-root"></div>
    <script>
    var fbLoaded = false;
    window.fbAsyncInit = function() {
        FB.init({
          appId      : 'YOUR_APP_ID', // App ID
          //channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
          status     : true, // check login status
          cookie     : true, // enable cookies to allow the server to access the session
          xfbml      : true  // parse XFBML
        });
        fbLoaded = true;
        // Additional initialization code here
    
    };
    
    function postForm() {
        var msg = document.myForm.msg.value;
        // do form validation here, e.g:
        if(!msg.length) {
            alert("You should enter a message!");
            return false;
        }
    
        // do we need to post to Facebook?
        if(document.myForm.toFB.checked) {
            // is the library loaded?
            if(!fbLoaded) {
                alert("Facebook JS-SDK is not yet loaded. Please try again later or uncheck Post To Facebook option");
                return false;
            }
    
            FB.getLoginStatus(function(response) {
                if (response.status === 'connected') {
                    var uid = response.authResponse.userID;
                    var accessToken = response.authResponse.accessToken;
                    /* 
                    *  message can be posted to Facebook directly
                    *  using the FB.api method or accessToken
                    *  can be sent to the server and do the call
                    *  from there
                    */
                    myAjaxCall(msg, accessToken);
                } else {
                    // status is either not_authorized or unknown
                    FB.login(function(response) {
                        if (response.authResponse) {
                            var accessToken = response.authResponse.accessToken;
                            myAjaxCall(msg, accessToken);
                        } else {
                            alert('User cancelled login or did not fully authorize.');
                        }
                    }, {scope: 'publish_stream'});
                }
            });
        } else {
            myAjaxCall(msg);
        }
        return false;
    }
    
    function myAjaxCall(m,a) {
        alert("Here you make the ajax call\nMessage: " + m + "\nAccess Token: " + a);
    }
    
      // Load the SDK Asynchronously
      (function(d){
         var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement('script'); js.id = id; js.async = true;
         js.src = "//connect.facebook.net/en_US/all.js";
         ref.parentNode.insertBefore(js, ref);
       }(document));
    </script>
    
    <form id="myForm" name="myForm" action="post" onSubmit="return postForm()">
    <p><label>Your Message:</label><br/><textarea name="msg"></textarea></p>
    <p><label>Post to Facebook?</label><input type="checkbox" value="1" name="toFB" /></p>
    <p><input type="submit" value="Submit"></p>
    </form>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please tell me I'm doing something stupid in setting up my wcf rest service.
Please tell me what is use of: <add assembly=*/> because of this i am
Please tell me I'm missing something obvious here. I am getting a syntax error
Please tell me, Is Jetty non-blocking web server by default or not? For example,
Please tell me a way on how to make that if the user has
Please tell me how can i raise event just after user change his position
Please tell me why this is not working. It was working but has inexplicably
Please tell a way to know in my app, once user ON/OFF the GPS,
Please tell me what is the Qt equivalent function for glutswapbuffers()..
Please tell me why my window doesn't render. Below is the javascript that i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.