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 6332121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:12:05+00:00 2026-05-24T18:12:05+00:00

So I have some code where I grab the logged in users Facebook ID

  • 0

So I have some code where I grab the logged in users Facebook ID through their API. That looks like this:

var facebookId = "";
facebookId = getFBIdSafe();

The method call to get it looks like this:

function getFBIdSafe()
{
    FB.api('/me', function(response) {
        if (!response || response.error) {
            return "";
        } else {
            return response.id;
        }
    });
}

What’s happening is, I call this method as I showed above, and then go and do other stuff, one of those things being an AJAX call to my own server passing in the facebookId that was “set”. Problem is, it’s never set.

I’d prefer not to put the FB.api calls all over the place in my code just so I can put my other code in the success call back of it. How can I cleanly take care of this and make sure that this Id always comes back before I make the call to my own server?

P.S. It doesn’t execute this code unless the user is logged in to Facebook in the first place – that check happens based on a status marker on the site though – so it’s not the same issue.

  • 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-24T18:12:06+00:00Added an answer on May 24, 2026 at 6:12 pm

    If what you want is avoid retrieving the current user’s FB Id, then you should delay all your server calls until the id is obtained. If you have jQuery or are willing to use jQuery, you can use a $.Deferred() to defer all your server calls until the FB Id is retrieved. I’m suggesting to do something lke this:

    var FBIdLoad = $.Deferred();
    function getFBIdSafe()
    {
        FB.api('/me', function(response) {
            if (!response || response.error) {
                FBIdLoad.resolveWith("");
            } else {
                FBIdLoad.resolveWith(response.id);
            }
        });
    }
    
    [...]
    
    FBIdLoad.done(function(FBId){
      /* Your server call with the Id */
    }
    

    All functions passed to the FBIdLoad.done will automatically be executed if the object was already resolved (when the FB.Api responds with the id), and always receive the requested Id.

    Hope it helps,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code like this in a winforms app I was writing to
I have some code like this: If key.Equals(search, StringComparison.OrdinalIgnoreCase) Then DoSomething() End If I
I have some output, which looks like this: blah blah garbage text more garbage
I have some Python code that uses Paramiko to grab build files from a
I have some as3 code under development that I'd like to migrate to as2
I have some code which collects points (consed integers) from a loop which looks
I have some code in a javascript file that needs to send queries back
I have some code that gives a user id to a utility that then
I have some code that uses xsl and xml. The Xml control is on
So far, I have some working code that goes into a list of servers

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.