Solved

Facebook Social Login: Fill form fields with details from Facebook



Show first post

36 replies

Userlevel 3

Hey Augusto

Are you still seeing this issue?

I visited the page and it seems to work just fine. If you are still running into issues shoot a email to support@unbounce.com and address it to me. Let me know what browsers/popup blocks are affecting it and i’ll see if I can give any helpful tips

Hello Johnny. I have been wrestling with this for days now. Everyhting works, except the crucial fact that popup blockers still block the facebook login dialog.

Check it out at: www.getqounter.com

Everything in now find, the template that i bought on time forest is include a javascript that block the Facebook connect, now it’s just perfect

Userlevel 3

Hey Maxime

It looks like you got this working now. Did you run into any other issues? I just tested out your page and it worked just fine. If your still having issues please detail them further.

1 - Javascript is before body end tag ?
2- Button url Pass thought url parameter ?
here my page : http://unbouncepages.com/browzin/ not working

Thanks!

Userlevel 3

Hey there!

Sorry about that. There’s a small bit of code that i’ve now added that should fix this issue.

Grab the updated script and give it another go!

<script>
  /**
    * Do not remove this section; it allows our team to troubleshoot and track feature adoption. 
    * TS:0002-13-010
  */

  function setFormValues(response) {
    
    // ***UPDATE FIELDS BELOW***
    //Adjust field IDs on the left with the field IDs on your form
    $('#email').val(response.email);
    $('#name').val(response.name);
      
    //Uncomment the lines below if you require the additional data
      
    //$('#firstNameField').val(response.first_name);
    //$('#lastNameField').val(response.last_name);
    //$('#linkField').val(response.link);
    //$('#genderField').val(response.gender);
    
    //The form willl submit by default. To disable this comment out the line below
    document.querySelector('.lp-pom-form button').click()
  }
  

  function statusChangeCallback(response) {
    if (response.status === 'connected') {
      fillForm();
    } else if (response.status === 'not_authorized') {
      triggerLogin();
    } else {
      triggerLogin();
    }
  }
  
  // Show Login Window
  function triggerLogin() {
    
   FB.login(function(response) {
     if (response.status === 'connected') {
         fillForm(); 
        }
   }, {scope: 'public_profile,email'}); 
  }
  
  // Called when your Facebook button is clicked
  function checkLoginState() {
    FB.getLoginStatus(function(response) {
      statusChangeCallback(response);
    });
  }

  // Update appId below to reflect your Facebook Apps ID
  window.fbAsyncInit = function() {
  FB.init({
    appId      : '552705011513631',
    cookie     : true, 
    xfbml      : true, 
    version    : 'v2.0',
    status     : true
  });
  };

  (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'));
  
  function fillForm() {
  
  // Update the variable below with the fields you wish to obtain
  // See the full list of fields here:
  // https://developers.facebook.com/docs/graph-api/reference/user
    var requestedFields = {
      fields: 'name, first_name, last_name, email'
    };
    
    FB.api('/me', requestedFields, function(response) {
      setFormValues(response);
    });
  }
</script>

I got this to work successfully with the form collecting the name and email but the problem is that the Facebook log-in pop-over is blocked the first time you click it. Is there a way to ensure the pop-up is never blocked?

Userlevel 3

Hey Kurtis - Increasing the scope should do the job. We have a ticket open so lets dig into this together to figure this out.

Just sent you a reply now!

This is awesome! I’ve used this to retrieve the email address, first name, and last name successfully.

The only other items I would like to retrieve is the hometown and province. Is this possible?

I updated the scope to include user_location and user_hometown.

Userlevel 3

Hey Michael - We don’t have a built in solution at the moment. However I put together a solution that should work in filling your forms with basic Facebook information. I’d be happy if you could give it a try and let me know if it works for your use case.

Add the script below to your ‘javascript’ box in the page builder

https://gist.github.com/johnnyopao/0f…

Be sure to update the section in the code labelled “UPDATE FIELDS BELOW” with your own fields IDs

To find the ID of your Unbounce fields open up the form builder, select a field, and look at the grey text below your field label. The grey value is the ID for that field.

Once your form fields are configured drop a button on your page and set its URL to:

javascript:checkLoginState();

This will get the button working under the domain ‘unbouncepages.com’. However if you wish to use this under your own domain you’ll need to configure some settings within Facebook itself.

Keep in mind you’ll only need to follow the instructions below for the first time you setup your Facebook ‘app’.

One time setup: setting up your own Facebook form app

Head over to https://developers.facebook.com/ and enable access to your developer account.

At the top menu select ‘Apps > Create a new app’

Set your apps display name and choose a category. Once that’s done select ‘Settings’ from the left menu.

Set the ‘Contact Email’ and select “Add Platform”. Choose ‘Website’ and define your domain URL.

From the left menu select ‘Status & Review’. Toggle the switch to turn your app ‘Live’

Your app is now configured! The last step is to obtain your App ID. Select ‘Dashboard’ from the menu and copy your ‘App ID’

Head back over to the Facebook form fill script and replace the App ID with your own:

That’s it! Remember this configuration only needs to be done once, afterwards you simply need to paste the updated script on your page and set your button to javascript:checkLoginState();

Reply