Facebook API wrapper for AngularJS, you don't have to worry about the configuration and working principles of Facebook JS SDK, you have only to code using our API.
Ready and easy to use.
The module is now under developing, in the next weeks the module will be completed and we're going to put online the official docs.
##Configuration
- Download the library clicking here or use
bower install ng-facebook-api
- Include Facebook JS SDK, only the SDK not the initialization
window.fbAsyncInit
andFB.init
- Modify your application inject the
ng-facebook-api
- In your application config, you must setup the facebookProvider with your Facebook App settings. The settings are used in FB.init
- If your app uses extra permissions that require user approval, set in your config. You can set permissions also in the controller, obviously before using login.
Here an example of configuration:
angular
.module('<your-app-name>',['ng-facebook-api'])
.config(function( facebookProvider) {
/**
* Here the list of params used to configure the provider
* @param appId
* @param status
* @param xfbml
* @param cookie
* @param api-version
*/
facebookProvider.setInitParams('your-fb-app-id',true,true,true,'v2.1');
//if your app use extra permissions set it
facebookProvider.setPermissions(['email','read_stream']);
});
Important: You must include the JS SDK in your
Not necessary from version 0.1.2<head>
or in method .run(function(){})
of angular app.
##Usage
The provider permits to have an easy access to the most used api (like user info retriving, avatar, etc..) but it also permits, thanks to api
method, to used all methods of Graph API.
Every methods check the login status and if user isn't logged, it launches the login procedure. Anyway the provider has public methods login
and checkLoginStatus
to implement your custom flows.
In your controller listen on the $rootScope
the event fb.init
module.controller('MainCtrl', function ($rootScope,$scope, facebook) {
$rootScope.$on("fb.init",function(){
console.log("SDK Ready");
});
});
Run the method that you need. For instance: getUser
to obtain available user information.
module.controller('MainCtrl', function ($rootScope,$scope, facebook) {
$rootScope.$on("fb.init",function(){
console.log("SDK Ready");
facebook.getUser().then(function(r){
console.log(r.user); //User data returned;
console.log(r.authResponse); //Token auth, id etc..
}, function(err){
console.log("Ops, something went wrong...");
});
});
});
###Documentation
The official docs wiki is here
- API_METHOD | The HTTP method that you can use to call the api.
- PICTURE_TYPE | When you get user profile image use this to indicate a pre-specified size of picture.
- api(path, method, params) | It permits to call the Graph API
- checkLoginStatus() | It checks if user isn't logged and launch login procedure.
- getUser(id, fields) | It retrives available user (depends on requested permissions) information.
- getUserPicture(id,fields) | It retrives user's profile picture.
- login()
- logout()
- setPermissions(permissions) | It set the permissions that the Facebook App need to do it work.
- setAutomaticLoginFlow(bool) | It permits to choose if use the automatic login flow (every time is needed) or implements custom login flow.
##Versions & Changelog
Bug Fixing:
-
In checkLoginStatus you can now choose if force login or not
-
Added integration with async FB SDK loading (you don't have to load manually the sdk)
Bug fixing:
First stable version.
Version: 0.2.0
- Minor bug fixing
- New easy method:
- getUserFeed() -> It fetches user feed post.
- uploadPhoto() -> It permits to upload a photo from form or url.
- createPost() -> It permits to post on user's feed.
- New configuration method:
- Disable/enabled autologin
This project is released over MIT license