Back to home

FacebookService (class exported as FacebookService)

You only need to inject this service in your application if you aren't using FacebookModule.

link Usage
import { FacebookService, InitParams } from 'ngx-facebook-sdk';

constructor(private fb: FacebookService) {

  const params: InitParams = {

  };

  fb.init(params);

}
link Instance Methods link init

This method is used to initialize and setup the SDK.

Param Type Details Default
params InitParams

Initialization parameters


link api

This method lets you make calls to the Graph API

Param Type Details Default
path string

The Graph API endpoint path that you want to call.

method (optional) string

The HTTP method that you want to use for the API request.

get
params (optional) Object

An object consisting of any parameters that you want to pass into your Graph API call.

Example usage of api:

this.fb.api('somepath')
.then(res => console.log(res))
.catch(e => console.log(e));

link ui

This method is used to trigger different forms of Facebook created UI dialogs. These dialogs include:

Param Type Details Default
params UIParams

A collection of parameters that control which dialog is loaded, and relevant settings.


link getLoginStatus

This method allows you to determine if a user is logged in to Facebook and has authenticated your app.

Param Type Details Default
forceFreshResponse (optional) boolean

Force a fresh response.

false

link login

Login the user

Param Type Details Default
options (optional) LoginOptions

Login options

Example usage of login:

// login without options
this.fb.login()
  .then((response: LoginResponse) => console.log('Logged in', response))
  .catch(e => console.error('Error logging in'));

// login with options
const options: LoginOptions = {
  scope: 'public_profile,user_friends,email,pages_show_list',
  return_scopes: true,
  enable_profile_selector: true
};
this.fb.login(options)
  .then(...)
  .catch(...);

link logout

Logout the user

Example usage of logout:

this.fb.logout().then(() => console.log('Logged out!'));

link getAuthResponse

This synchronous function returns back the current authResponse.

Example usage of getAuthResponse:

import { AuthResponse, FacebookService } from 'ngx-facebook-sdk';

...

const authResponse: AuthResponse = this.fb.getAuthResponse();