Coder Social home page Coder Social logo

ngfacebook's Introduction

Angular Facebook Build Status

Angular service to handle facebook

Installation

  1. Download the package:
    1. download using npm: npm install ng-facebook
    2. download using the zip file
    3. download using bower: bower install ng-facebook
  2. Modify your application to include ngFacebook in your application dependencies
  3. Configure the ngFacebook module using the configuration steps outlined in the section titled "Configuration" below.
  4. Load the Facebook SDK for javascript, BUT DO NOT call FB.init or set window.fbAsyncInit. These steps are automatically done by the ngFacebook module.

Example:

angular.module('<your-app>', ['ngFacebook'])

.config( function( $facebookProvider ) {
  $facebookProvider.setAppId('<your-facebook-app-id>');
})

.run( function( $rootScope ) {
  // Cut and paste the "Load the SDK" code from the facebook javascript sdk page.
  
  // Load the facebook SDK asynchronously
  (function(){
     ...
   }());
})

;

var DemoCtrl = function ($scope, $facebook) {
  ...
  function refresh() {
    $facebook.api("/me").then( 
      function(response) {
        $scope.welcomeMsg = "Welcome " + response.name;
      },
      function(err) {
        $scope.welcomeMsg = "Please log in";
      });
  }
};

For more details check out this plunker which uses ngFacebook.

Configuration

You must configure your facebook application ID in your app, for example:

app.config(function(FacebookProvider) {
  $facebookProvider.setAppId(11111111111);
});

Additional configurations

You can also configure the following properties. Both set and get methods are available for each property.

  1. permissions(<string>) - permissions required by your app.

    Example:

     $facebookProvider.setPermissions("email,user_likes");
    
  2. customInit(<object>) - the parameters to pass to FB.init(). The 'appId' parameter is automatically specified using the value passed to '$facebookProvider.setAppId()', however the remaining parameters are configurable.

    Example to set:

     $facebookProvider.setCustomInit({
       channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html',
       xfbml      : true
     });
    
  3. version(<string>) - specify the version of the api (2.0 by default).

    Example to set:

     $facebookProvider.setVersion("v2.2");
    

Using

Methods

  1. $facebook.config(property) - Return the config property.

  2. $facebook.getAuthResponse() - Return the AuthResponse(assuming you already connected)

  3. $facebook.getLoginStatus() - Return promise of the result.

  4. $facebook.login() - Logged in to your app by facebook. Return promise of the result.

  5. $facebook.logout() - Logged out from facebook. Return promise of the result.

  6. $facebook.ui(params) - Do UI action(see facebook sdk docs). Return promise of the result.

  7. $facebook.api(args...) - Do API action(see facebook sdk docs). Return promise of the result.

  8. $facebook.cachedApi(args...) - Do API action(see above), but the result will cached. Return promise of the result.

  9. $facebook.setVersion(version) - Set another SDK version

  10. $facebook.getVersion() - Get current SDK version Example:

     app.controller('indexCtrl', function($scope, $facebook) {
       $scope.user=$facebook.cachedApi('/me');
     });
    

Events

The service will broadcast the facebook sdk events with the prefix fb..

In return you will get the next arguments to your $on handler: event,response,FB (FB is the facebook native js sdk).

  1. fb.auth.login
  2. fb.auth.logout
  3. fb.auth.prompt
  4. fb.auth.sessionChange
  5. fb.auth.statusChange
  6. fb.auth.authResponseChange
  7. fb.xfbml.render
  8. fb.edge.create
  9. fb.edge.remove
  10. fb.comment.create
  11. fb.comment.remove
  12. fb.message.send

For additional information about the events see the sdk docs.

License

This project is released over MIT license

Sponsors

Thanks to our sponsors for this project:

  1. GoDisco
  2. JetBrains - for providing the great IDE PhpStorm

Authors

  1. Almog Baku - by GoDisco
  2. Amir Valiani
  3. Tal Gleichger - by GoDisco

ngfacebook's People

Contributors

almogbaku avatar avaliani avatar danjesus avatar johndoesenior avatar kukac7 avatar mickeywu avatar urish avatar lukasz-zak avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.