Git Product home page Git Product logo

ember-cli-facebook-js-sdk's Introduction

Ember Observer Score

Ember-cli-facebook-js-sdk

Simple Facebook SDK for Javascript addon for your Ember CLI app.

This addon lets you interact with the Facebook API using Promises as you would usually do with any async operation in your Ember app. The same API is used in the addon so that you can easily refer to the Facebook SDK for Javascript reference doc for details on the usage.

The methods implemented are:

  • Core Methods
    • init
    • api
    • ui
  • Facebook Login Methods
    • getLoginStatus
    • login
    • logout
    • getAuthResponse
  • Misc
    • XFBML.parse

Installation

  • ember install ember-cli-facebook-js-sdk

Upgrade from 0.0.4

From version 1.0.0 ember-cli-facebook-js-sdk implements a service, before it was a simple ES6 module you should import. If you prefer to stick to the old version, checkout the 0.0.4 tag.

Usage and configuration

Configuration

Before using the Facebook SDK for Javascript you need to include it in your HTML. The more convenient way to do it is by using the addon service's FBInit method. To do so, you must configure the parameters to use to initialize the Facebook SDK in your config/environment.js file in the FB key. The following is a basic example of such a configuration:

  FB = {
    appId: 'YOUR APP ID',
    version: 'v2.7',
    xfbml: true
  }

You need to replace YOUR APP ID with your own Facebook App ID (which can be found in the Facebook developer dashboard) and also set the version to Facebook API version you would like to use.

Skipping Facebook SDK init

Note, if you use other addons or if you prefer to initialize the Facebook SDK for Javascript by your own, you must configure the addon to skip the initialization process:

  FB = {
    skipInit: true
  }

Usage

Whenever you need to interact with Facebook SDK, you must inject the service in your code and use it as you would do with the original SDK. Remember that async functions that would normally require a callback, here return a Promise.

If you find yourself, needing the service in all your controllers you could think of injecting the service by default in your controller like the following:

export function initialize(application) {
  application.inject('controller', 'fb', 'service:fb');
}

export default {
  name: 'fb',
  initialize
};

Initialize the Facebook JS SDK

Before using the Facebook SDK you must be sure to have initialized it. The most convenient way is to call the FBInit function of the fb service in your Application route:

import Ember from 'ember';

export default Ember.Route.extend({
  fb: Ember.inject.service(),

  beforeModel() {
    return this.get('fb').FBInit();
  }
})

Usage example

You can now use the add-on to, for example, retrieve the current Facebook user data from your route:

import Ember from 'ember';

export default Ember.Route.extend({
  fb: Ember.inject.service(),

  model() {
    return this.get('fb').api('/me');
  }
});

Forcing XFBML tag re-parsing

The loading and initialization of the Facebook SDK is asynchronous so it may happen that you use XFBML tags and these are not properly parsed from the SDK: this could happen, for example, because you add such a tag as part of a component mark-up which is added to the DOM after the parsing init script already run. In such a case you may find it useful to rescue to call the xfbml_parse function explicitly:

import Ember from 'ember';

export default Ember.Component.extend({
  fb: Ember.inject.service(),

  didInsertElement() {
    return this.get('fb').xfbml_parse();
  }
});

You may also try to schedule the same code to run afterRender from your route's controller hook.

Example app

You can find an example app which make use of the addon in the I have been to repo.

Running Tests

TODO: I need to find a way to run test with a valid (never expiring) access token for a test user. Before running tests, substitute any occurence of YOUR-APP-ID and YOUR-FB-TOKEN in tests/unit/services/fb-test.js with respectively your Facebook App ID and access token.

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

ember-cli-facebook-js-sdk's People

Contributors

bugduino avatar ember-tomster avatar joelalejandro avatar mattmcmanus avatar potomak 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.