Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Sample files for Phonegap + AngularJS + Facebook walkthrough at http://noellh.com/blog/phonegap-angularjs-facebook/

View app.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
angular.module('demoapp', ['ngRoute', 'demoapp.services', 'demoapp.controllers', 'ezfb'])
 
.config(function (ezfbProvider) {
ezfbProvider.setInitParams({
appId: '12345',
nativeInterface: CDV.FB,
useCachedDialogs: false
});
 
ezfbProvider.setLoadSDKFunction(function ($rootScope, ezfbAsyncInit) {
$rootScope.ezfbAsyncInit = ezfbAsyncInit;
});
})
 
.config(function ($routeProvider) {
$routeProvider
.when('/', {
controller: 'MainCtrl',
templateUrl: 'partials/main.html'
})
.when('/view', {
controller: 'ViewCtrl',
templateUrl: 'partials/view.html'
})
.otherwise({redirectTo: '/'});
});
View app.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
angular.module('demoapp.controllers', ['ezfb'])
.controller('MainCtrl', ['$scope', 'ezfb', function ($scope, ezfb) {
$scope.status = "It works!";
 
$scope.init = false;
 
updateLoginStatus();
 
$scope.login = function () {
ezfb.login(function (res) {
if(res.status == 'connected') {
updateLoginStatus(updateMe);
}
}, {scope: 'email'});
};
 
$scope.logout = function () {
ezfb.logout(function () {
updateLoginStatus(updateMe);
});
};
 
$scope.me = function() {
updateMe();
};
 
function updateMe() {
ezfb.api('/me', function(response) {
$scope.user = response;
});
}
 
function updateLoginStatus() {
ezfb.getLoginStatus(function (res) {
$scope.loginStatus = res;
if(res.status == 'connected') {
updateMe();
}
});
}
}])
.controller('ViewCtrl', ['$scope', function ($scope) {
$scope.status = "Also totally works!";
}]);
View app.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<h2> Main View: {{ status }} </h2>
 
<div ng-show="!init">
<button ng-click="ezfbAsyncInit(); init = true;">FB Initialize</button>
</div>
<div ng-show="init">
<button ng-click="login()">Connect with Facebook</button>
<button ng-click="me()" ng-show="loginStatus.status == 'connected'">Update me!</button>
<button ng-click="logout()" ng-disabled="!init || !loginStatus || loginStatus.status != 'connected'">Logout</button>
</div>
 
<ul>
<li>Hi {{ user.name }}!</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.