Munded
Munded

Reputation: 97

Cannot log into Facebook via ngFacebook on angularjs app

I'm trying to set up log in via ngFacebook and I am unable to log in to facebook. I cannot even get anything to console log after calling '$facebook.log()'.

My angular app:

'use strict';

angular
  .module('fmcFrontendApp', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch',
    'ngFacebook'
  ])
  .config(function ($facebookProvider) {

    $facebookProvider.setAppId('///////////');

    $facebookProvider.setCustomInit({
        version: 'v2.2',
        channelUrl : '/index.html',
        xfbml : true
    });

    $facebookProvider.setPermissions('email, public_profile');
  })

  .run(function() {
          (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')); 
  })

  .controller( 'fbCtrl', [ '$facebook', function($facebook) {
    var self = this;

    self.isLoggedIn = false;
    self.login = function() {
      console.log('hello')
      $facebook.login().then(function() {
        console.log("Please see me")
        refresh();
      });
    }

    function refresh() {
      $facebook.api("/me").then(
        function(response) {
          console.log(response);
          self.welcomeMsg = "Welcome " + response.name
          self.isLoggedIn = true
        },
        function(err) {
          self.welcomeMsg = "Please log in";
        });
    }

    refresh();

  }]);

and the relevant angular elements:

  <button id="fb-login" type="button" ng-click="fbCtrl.login()" ng-hide="fbCtrl.isLoggedIn" class="btn btn-default navbar-btn"> Login </button>

<div id="fb-root"></div>

any help anyone can give would be greatly appreciated! I'm really racking my brain and can't figure out what is going on!

Upvotes: 2

Views: 478

Answers (3)

Tushar Jain
Tushar Jain

Reputation: 83

I was facing same issue with ngFacebook,but after including this script in index.html

src="http://connect.facebook.net/en_US/all.js"

This issue resolves.

Upvotes: 0

Phoebe
Phoebe

Reputation: 198

The solution was to remove:

 <script src="http://connect.facebook.net/en_US/all.js"></script>

from the HTML file.

Upvotes: 3

Munded
Munded

Reputation: 97

Still haven't fixed it but it appears to be a bug in Chrome!

Upvotes: 0

Related Questions