import { Injectable } from '@angular/core' ; import { AuthResponse } from '../models/auth-response' ; import { InitParams } from '../models/init-params' ; import { LoginOptions } from '../models/login-options' ; import { LoginResponse } from '../models/login-response' ; import { LoginStatus } from '../models/login-status' ; import { UIParams } from '../models/ui-params' ; import { UIResponse } from '../models/ui-response' ; declare var FB ; hidden export type ApiMethod = 'get' | 'post' | 'delete' ; shortdesc description usage @ Injectable ( { providedIn : 'root' } ) export class FacebookService { param params { InitParams } returns { Promise < any > } init ( params ) { try { return Promise . resolve ( FB . init ( params ) ) ; } catch ( e ) { return Promise . reject ( e ) ; } } usage param path { string } param method { string } param params { Object } returns { Promise < any > } api ( path , method = 'get' , params = { } ) { return new Promise < any > ( ( resolve , reject ) => { try { FB . api ( path , method , params , ( response ) => { if ( ! response ) { reject ( ) ; } else if ( response . error ) { reject ( response . error ) ; } else { resolve ( response ) ; } } ) ; } catch ( e ) { reject ( e ) ; } } ) ; } param params { UIParams } returns { Promise < UIResponse > } ui ( params ) { return new Promise < any > ( ( resolve , reject ) => { try { FB . ui ( params , ( response ) => { if ( ! response ) reject ( ) ; else if ( response . error ) reject ( response . error ) ; else resolve ( response ) ; } ) ; } catch ( e ) { reject ( e ) ; } } ) ; } param forceFreshResponse { boolean } returns { Promise < LoginStatus > } getLoginStatus ( forceFreshResponse ? ) { return new Promise < LoginStatus > ( ( resolve , reject ) => { try { FB . getLoginStatus ( ( response ) => { if ( ! response ) { reject ( ) ; } else { resolve ( response ) ; } } , forceFreshResponse ) ; } catch ( e ) { reject ( e ) ; } } ) ; } usage param options { LoginOptions } returns { Promise < LoginResponse > } login ( options ? ) { return new Promise < LoginResponse > ( ( resolve , reject ) => { try { FB . login ( ( response ) => { if ( response . authResponse ) { resolve ( response ) ; } else { reject ( ) ; } } , options ) ; } catch ( e ) { reject ( e ) ; } } ) ; } usage returns { Promise < any > } logout ( ) { return new Promise < any > ( ( resolve , reject ) => { try { FB . logout ( ( response ) => { resolve ( response ) ; } ) ; } catch ( e ) { reject ( e ) ; } } ) ; } usage returns { AuthResponse } getAuthResponse ( ) { try { return < AuthResponse > FB . getAuthResponse ( ) ; } catch ( e ) { console . error ( 'ngx-facebook-sdk: ' , e ) ; } } }