Created
October 12, 2014 19:41
-
-
Save jBenes/61061ac3eea01d5e5f5e to your computer and use it in GitHub Desktop.
ng-fb-adapter - usage
This file contains hidden or 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
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