You only need to inject this service in your application if you aren't using FacebookModule
.
import { FacebookService, InitParams } from 'ngx-facebook-sdk';
constructor(private fb: FacebookService) {
const params: InitParams = {
};
fb.init(params);
}
Instance Methods
init
This method is used to initialize and setup the SDK.
Param | Type | Details | Default |
---|---|---|---|
params |
InitParams
|
Initialization parameters |
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. |
api
:
this.fb.api('somepath')
.then(res => console.log(res))
.catch(e => console.log(e));
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. |
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
|
Login the user
Param | Type | Details | Default |
---|---|---|---|
options (optional) |
LoginOptions
|
Login options |
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(...);
Logout the user
Example usage oflogout
:
this.fb.logout().then(() => console.log('Logged out!'));
This synchronous function returns back the current authResponse.
Example usage ofgetAuthResponse
:
import { AuthResponse, FacebookService } from 'ngx-facebook-sdk';
...
const authResponse: AuthResponse = this.fb.getAuthResponse();