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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:24:25+00:00 2026-05-29T07:24:25+00:00

The code below successfully triggers the FB.api() function when the button named button2 is

  • 0

The code below successfully triggers the FB.api() function when the button named “button2” is clicked however I am unable to trigger it from the button named “button1” event though I have verified that the button is triggering it’s click handler. If anyone could tell me what I’m doing wrong I’d appreciate it.

window.fbAsyncInit = function() {      
          FB.init({ appId: 'xxxxxxxxxxxxxxx', 
            status: true, 
            cookie: true,
            xfbml: true,
            oauth: true
                  });

         function updateButton(response) {
           var button1 = document.getElementById('subbtn');;
           var button2 = document.getElementById('fb-auth');

           button1.onclick = function(response){
             alert("Button1 Clicked");
             FB.api('/me', function(response) {
               alert("FB.api Triggered");
                                           });
                                                };

           if (response.authResponse) {
             //user is already logged in and connected
             var userInfo = document.getElementById('user-info');
             FB.api('/me', function(response) {
               userInfo.innerHTML = '<img src="https://graph.facebook.com/' + response.id + '/picture">' + response.name;
               button2.innerHTML = 'Logout';
                                               });                             
              button2.onclick = function() {
                FB.logout(function(response) {
                  var userInfo = document.getElementById('user-info');
                  userInfo.innerHTML="";
                                           });
                                            };
                                        } else {
              //user is not connected to your app or logged out
              button2.innerHTML = 'Login';
              button2.onclick = function() {
                FB.login(function(response) {
              if (response.authResponse) {
                    FB.api('/me', function(response) {
                      alert("FB.api triggered");
                  var userInfo = document.getElementById('user-info');
                  userInfo.innerHTML = '<img src="https://graph.facebook.com/'  + response.id + '/picture" style="margin-right:5px"/>' + response.name;
                                                   });     
                                         } else {
                      //user cancelled login or did not grant authorization
                                                     }
                                              }, {scope:'email'});      
                                              }
                                                 }
                                                 }

           // run once with current status and whenever the status changes
           FB.getLoginStatus(updateButton);
           FB.Event.subscribe('auth.statusChange', updateButton);   
                                            };

           (function() {
             var e = document.createElement('script'); e.async = true;
             e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
             document.getElementById('fb-root').appendChild(e);
                         }());
  • 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-29T07:24:26+00:00Added an answer on May 29, 2026 at 7:24 am

    It looks like the difference between the two onclicks is that you are calling FB.login before you call FB.api in the button2 click event, but not in the button1 event:

    button1.onclick = function(response){
                 alert("Button1 Clicked");
                 FB.api('/me', function(response) {
    

    vs

    button2.onclick = function() {
                    FB.login(function(response) {
                  if (response.authResponse) {
                        FB.api('/me', function(response) {
    

    I’m guessing if you click button2 and then button1, that button1’s handler works?

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

Sidebar

Related Questions

I have the code below and everything works but the button click function on
I wrote the code below that successfully gets a random line from a file;
I have successfully scheduled local notifications in my app using the code below: Class
My code shown below will successfully return an array of values using print_r. How
The code below works insomuch that I can successfully download the directory recursively. But,
I want to run the Java code below in Matlab. It ran successfully in
newbie here. I successfully created a chat server using c# (server partial code below,
I have an xml feed from the youtube API. So far I have successfully
The code below successfully fades in one testimonial for 6 seconds, waits 3 seconds,
I can build and execute the code below successfully : IplImage* img = cvLoadImage(C:\\hello.jpg);

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.