Created
August 2, 2017 19:27
-
-
Save vladimir-ivanov/a53641854fcf07483a346a96e235cd65 to your computer and use it in GitHub Desktop.
facebook graph api sdk angular 2 / 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Inject, Injectable, InjectionToken} from '@angular/core'; | |
import {Observable} from 'rxjs/Observable'; | |
import {AsyncSubject} from "rxjs/AsyncSubject"; | |
export let FacebookSdk = new InjectionToken<any>("FacebookSdk"); | |
@Injectable() | |
export class FbRequestService { | |
constructor(@Inject(FacebookSdk) private facebookSdk) { | |
} | |
request(path: string, params: any): Observable<any> { | |
const sub = new AsyncSubject(); | |
this.facebookSdk.api(path, params, (response) => { | |
if (!response || response.error) { | |
sub.error(response.error || "Unspecified"); | |
} else { | |
sub.next(response); | |
} | |
sub.complete(); | |
}); | |
return sub; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment