PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 16, 2022

[FIXED] Why did this Facebook Login code stop working last night for no apparent reason?

 July 16, 2022     facebook-login, javascript     No comments   

Issue

The Facebook Login button on my site worked fine until late last night, although no changes were made to the site by me (only person who still has access). Now when you click it, nothing happens. And I don't see any issues specified in the Console (using Google Chrome):

https://www.babyhunch.com/login

My friend added this code years ago and I'm not clear on exactly what's happening so if anyone can spot what the issue might be, please let me know. Not asking to fix or rewrite, just hoping you someone can get me down the right path. NOTE: I hid a few numbers in the appID since I assume that shouldn't be shared publicly.

window.fbAsyncInit = function() {
    // FB JavaScript SDK configuration and setup
    FB.init({
      appId      : '39???????324018', // FB App ID
      cookie     : true,  // enable cookies to allow the server to access the session
      xfbml      : true,  // parse social plugins on this page
      version    : 'v2.8' // use graph api version 2.8
    });
};

// Load the JavaScript SDK asynchronously
(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

// Facebook login with JavaScript SDK
function fbLogin() {
    FB.login(function (response) {
        if (response.authResponse) {
             // Send user data to database via AJAX
            getFbUserData(function(){
            window.location.replace("/my-pools"); //pass this anonymous function as callback of getFbUserData
            });
        } else {
           /* document.getElementById('status').innerHTML = 'User cancelled login or did not fully authorize.';*/
        }
    }, {scope: 'email'});
}

    
// Save user data to the database
function saveUserData(userData, callback){ //new parameter CALLBACK
    $.post('fb-login-process.php', {oauth_provider:'facebook',userData: JSON.stringify(userData)}, function(data){ callback(); /* execute callback when XHR completes */ return true; });
} 
    
// Fetch the user profile data from facebook
function getFbUserData(callback){
    FB.api('/me', {locale: 'en_US', fields: 'id,first_name,last_name,email,link,gender,locale,picture'},
    function (response) {
        // Save user data
        saveUserData(response, callback);
    });
}
    

<!-- Facebook login or logout button -->
<a href="javascript:void(0);" onclick="fbLogin()" id="fbLink"><img class="continue-with-facebook" src="/images/continue-with-facebook.svg"/></a>

Solution

I am facing the same same issue using the JS SDK and on API version 10.0.

There is currently an outage / issue from facebooks side. You can see the details of the issue "JS SDK and Social Plugins Failure" here and the Bug report here.

The first place you should check for the status of APIs and SDKs is the "Facebook Platform Status" page which has identified this issue 6 hours ago.



Answered By - Devin Miller
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing