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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:41:39+00:00 2026-06-08T09:41:39+00:00

In my application I have a function like this one: getProfile = function() {

  • 0

In my application I have a function like this one:

getProfile = function() {
  FB.api('/me', function(response) {
    console.log(response);
  });
  return false;
};

Which requests the “me” object from the Facebook Graph API over JavaScript, and it works as expected when I attach it to the onClick event of a regular link or call it from the console directly, but when I try to call it from the Facebook log in button:

  <fb:login-button onlogin="getProfile()">
    Get Profile
  </fb:login-button>

I get the expected response only if I am logged out of Facebook and subsequently log in through the dialog; if I click the button while I’m already logged in, I get this:

Two identical requests to the "me" object.

And if I push the response to the browser:

getProfile = function() {
  FB.api('/me', function(response) {
    console.log(response);
    var
      profile = document.getElementById('profile'),
      p = document.createElement('p');
    p.innerHTML = response.first_name;
    profile.appendChild(p);
  });
  return false;
};

Of course I get two paragraphs with my name in them.

Can anyone spot what I’m doing wrong? So far my Googling has me convinced that this is related to the way the SDK handles log in events (firing on every page load) but I can’t figure out how I’m supposed to account for that in the application code.

  • 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-06-08T09:41:40+00:00Added an answer on June 8, 2026 at 9:41 am

    I believe the onlogin event fires when you load the page because you are logged into Facebook. Then, when your user clicks the button, it also triggers the event. If you’re not logged in in the first place, then the onlogin event doesn’t fire on load.

    UPDATE: to avoid this, simply don’t hook the getProfile to the onlogin event except inside an if statement based on the FB.getLoginStatus method http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/ Simply put, if you’re logged in, don’t attach an onlogin event, otherwise do an FB.Event.subscribe http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ on the onlogin event and your method will run whenever the user logs in through your XFBML-generated login button.

    FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
      //print the response data into the paragraph here
    } else if (response.status === 'not_authorized') {
      // the user is logged in to Facebook, 
      // but has not authenticated your app
      FB.event.subscribe( 'auth.login', function(){
        getProfile();
      });
    } else {
      // the user isn't logged in to Facebook.
    }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In an ASP.MVC application, I have a function defined in my _ViewStart.cshtml like this:
I have a function like this in one of my classes and then I
I have a function like this defined in one class: using System; using System.Collections.Generic;
I have Java application which sends pointer to function (callback) to some native dll
I have an application in VC++ which needs to execute a function provided to
i used to have a function defined like this (that is working fine under
I'm developing an HTML5 application. I want to parse an XML like this one:
I have the following code which works: $(document).ready(function() { var xhr = false; func_two();
I know a few questions have been asked like this one before, such as
In an ASP.NET MVC3 application I have a function that looks like: Public Sub

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.