Last active
December 21, 2015 07:19
-
-
Save whisher/6270204 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>AngularJS Fb Test</title> | |
</head> | |
<body> | |
<div id="fb-root"></div> | |
<h1>index.html test get rid of me</h1> | |
<div data-ng-app="app"> | |
<button ng-click="fbLogin()">FB connect</button> | |
<div data-ng-controller="fbCtrl"> | |
</div> | |
</div> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> | |
<script> | |
var BT = {}; | |
BT.channel = 'https://mysite.com/channel.html'; | |
BT.fbAppId = 'myappid'; | |
var app = angular.module( 'app', [] ); | |
app.controller("fbCtrl", function ($scope) { | |
}); | |
app.run(function($rootScope,Facebook) { | |
(function(d){ | |
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; | |
if (d.getElementById(id)) { | |
return; | |
} | |
js = d.createElement('script');js.id = id;js.async = true; | |
js.src = "//connect.facebook.net/it_IT/all.js"; | |
ref.parentNode.insertBefore(js, ref); | |
}(document)); | |
window.fbAsyncInit = function() { | |
FB.init({ | |
appId : BT.fbAppId, // App ID | |
channelUrl : BT.channel, // Channel File | |
status : true, // check login status | |
cookie : true, // enable cookies to allow the server to access the session | |
xfbml : true // parse XFBML | |
}); | |
$rootScope.fbLogin = Facebook.fbLogin; | |
}; | |
}); | |
app.factory('Facebook', function () { | |
function fbLogin(callback){ | |
FB.login(function(response) { | |
if (response.status==='connected') { | |
var uid = response.authResponse.userID; | |
callback(response.authResponse); | |
} | |
}, | |
{scope:'email'}); | |
} | |
return { | |
fbLogin : fbLogin | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment