Skip to content

Instantly share code, notes, and snippets.

@jBenes
Created October 12, 2014 19:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jBenes/61061ac3eea01d5e5f5e to your computer and use it in GitHub Desktop.
Save jBenes/61061ac3eea01d5e5f5e to your computer and use it in GitHub Desktop.
ng-fb-adapter - usage
angular.module('myModule', [
'facebook-integration'
])
.config(function(..., fbAdapterProvider) {
var adapter = 'OpenFBAdapter';
if(window.cordova) {
adapter = 'facebookConnectPluginAdapter';
}
fbAdapterProvider.setSettings({appId: 'xxx'});
fbAdapterProvider.chooseAdapter(adapter);
})
.controller('MyCtrl', function($scope, fbAdapter) {
$scope.fb = {
loggedIn: false,
login: function() {
fbAdapter.login('email,publish_actions').then(function(response) {
if (response.status === 'connected') {
$scope.fb.loggedIn = true;
} else {
// err
}
});
},
logout: function() {
fbAdapter.logout().then(function(response) {
$scope.fb.loggedIn = false;
});
},
// check if logged
getLoginStatus: function(login) {
fbAdapter.getLoginStatus().then(function(res) {
if(res.status === 'connected') {
$scope.fb.loggedIn = true;
} else {
$scope.fb.loggedIn = false;
}
});
},
// get user info
me: function() {
fbAdapter.api('/me').then(function(response) {
$scope.user = response;
});
},
// publish status
setStatus: function(outfit) {
fbAdapter.showDialog({
method: "feed",
link:"http://xxx",
caption: "xxx"
}).then(function() {
// success
}).catch(function() {
// err
});
}
}
// check status after initialization is complete
fbAdapter.$promise.then(function() {
$scope.fb.getLoginStatus(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment